<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="generator" content="VuePress 2.0.0-beta.60">
    <script>
      (function() {
        const userMode = localStorage.getItem('vuepress-reco-color-scheme') || 'auto';
        const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;

        if (userMode === 'dark' || (userMode === 'auto' && systemDarkMode)) {
          document.documentElement.classList.toggle('dark', true);
        }
      })();
    </script>
    <title>Java 基础 | 阿派 | Apai Blog</title><meta name="description" content="Just playing around">
    <link rel="modulepreload" href="/assets/app-8a43a0f0.js"><link rel="modulepreload" href="/assets/framework-e1bed10d.js"><link rel="modulepreload" href="/assets/Java-basics.html-c0d3a063.js"><link rel="modulepreload" href="/assets/Java-basics.html-4a44925e.js"><link rel="prefetch" href="/assets/index.html-ef2f4f01.js" as="script"><link rel="prefetch" href="/assets/index.html-1013d654.js" as="script"><link rel="prefetch" href="/assets/index.html-a146dedc.js" as="script"><link rel="prefetch" href="/assets/index.html-f4b2eaea.js" as="script"><link rel="prefetch" href="/assets/index.html-e3ed352e.js" as="script"><link rel="prefetch" href="/assets/index.html-42ce2ab9.js" as="script"><link rel="prefetch" href="/assets/index.html-ec24ec9e.js" as="script"><link rel="prefetch" href="/assets/index.html-d3d8d7ce.js" as="script"><link rel="prefetch" href="/assets/index.html-9faf073b.js" as="script"><link rel="prefetch" href="/assets/index.html-9364b7dd.js" as="script"><link rel="prefetch" href="/assets/index.html-fc0fb462.js" as="script"><link rel="prefetch" href="/assets/index.html-603c6c19.js" as="script"><link rel="prefetch" href="/assets/index.html-0349deb8.js" as="script"><link rel="prefetch" href="/assets/index.html-09405a87.js" as="script"><link rel="prefetch" href="/assets/index.html-91577c59.js" as="script"><link rel="prefetch" href="/assets/index.html-552ae255.js" as="script"><link rel="prefetch" href="/assets/index.html-424369c4.js" as="script"><link rel="prefetch" href="/assets/index.html-1dfc0069.js" as="script"><link rel="prefetch" href="/assets/index.html-ec62f595.js" as="script"><link rel="prefetch" href="/assets/index.html-4621ef22.js" as="script"><link rel="prefetch" href="/assets/index.html-e189ec13.js" as="script"><link rel="prefetch" href="/assets/index.html-b424a45b.js" as="script"><link rel="prefetch" href="/assets/index.html-623952a8.js" as="script"><link rel="prefetch" href="/assets/index.html-cedcb7c8.js" as="script"><link rel="prefetch" href="/assets/index.html-07f61d2f.js" as="script"><link rel="prefetch" href="/assets/index.html-9ef01f1e.js" as="script"><link rel="prefetch" href="/assets/index.html-dfa6d19f.js" as="script"><link rel="prefetch" href="/assets/index.html-23dd0955.js" as="script"><link rel="prefetch" href="/assets/index.html-1e7a4ff3.js" as="script"><link rel="prefetch" href="/assets/index.html-e12f154a.js" as="script"><link rel="prefetch" href="/assets/index.html-30de2d02.js" as="script"><link rel="prefetch" href="/assets/index.html-6a244983.js" as="script"><link rel="prefetch" href="/assets/index.html-8900b10e.js" as="script"><link rel="prefetch" href="/assets/index.html-b3210461.js" as="script"><link rel="prefetch" href="/assets/biaoqian-fenlei-moban.html-2db9524d.js" as="script"><link rel="prefetch" href="/assets/MuBan-Apai.html-5af383c8.js" as="script"><link rel="prefetch" href="/assets/guide.html-5aaed80e.js" as="script"><link rel="prefetch" href="/assets/Lu-aboutMe.html-82ee5401.js" as="script"><link rel="prefetch" href="/assets/kaishi.html-9d8493a0.js" as="script"><link rel="prefetch" href="/assets/Hobby-SheYing.html-3ac28a1b.js" as="script"><link rel="prefetch" href="/assets/Lu-aboutMe.html-96d10c31.js" as="script"><link rel="prefetch" href="/assets/Work-MaYun.html-5e497e8c.js" as="script"><link rel="prefetch" href="/assets/JavaAPI.html-ae8a1843.js" as="script"><link rel="prefetch" href="/assets/JavaBiKeng04.html-c9e75b16.js" as="script"><link rel="prefetch" href="/assets/JavaGongNeng03.html-6ca97faf.js" as="script"><link rel="prefetch" href="/assets/JavaJinJie02.html-eaabb81d.js" as="script"><link rel="prefetch" href="/assets/JavaMyUtil.html-e2cff404.js" as="script"><link rel="prefetch" href="/assets/MyBatisPlus.html-b608a85b.js" as="script"><link rel="prefetch" href="/assets/MySql.html-4bcdc408.js" as="script"><link rel="prefetch" href="/assets/MySqlFunction.html-23affe6f.js" as="script"><link rel="prefetch" href="/assets/RabbitMQ.html-2cc19b22.js" as="script"><link rel="prefetch" href="/assets/Redis.html-f7a014e9.js" as="script"><link rel="prefetch" href="/assets/ShiWuAffair.html-33f5c0c4.js" as="script"><link rel="prefetch" href="/assets/Spring.html-628746d6.js" as="script"><link rel="prefetch" href="/assets/SpringConfig.html-49f3c621.js" as="script"><link rel="prefetch" href="/assets/SpringPeiZhi.html-ac6df88a.js" as="script"><link rel="prefetch" href="/assets/SpringSecurity.html-057633f1.js" as="script"><link rel="prefetch" href="/assets/WebSocket.html-57d6fc97.js" as="script"><link rel="prefetch" href="/assets/DockerCompose.html-98ad6b52.js" as="script"><link rel="prefetch" href="/assets/Linux.html-43351365.js" as="script"><link rel="prefetch" href="/assets/Nginx.html-f1276de6.js" as="script"><link rel="prefetch" href="/assets/RabbitMQ_COPY.html-5cdb6370.js" as="script"><link rel="prefetch" href="/assets/Redis_COPY.html-486e1d26.js" as="script"><link rel="prefetch" href="/assets/Redis_CRUD.html-47e0af0f.js" as="script"><link rel="prefetch" href="/assets/BatJiaoBen.html-d2d2666a.js" as="script"><link rel="prefetch" href="/assets/DmShengChen.html-bb069d8e.js" as="script"><link rel="prefetch" href="/assets/EasyExcel.html-b1eb613d.js" as="script"><link rel="prefetch" href="/assets/GitLu.html-eae89aa5.js" as="script"><link rel="prefetch" href="/assets/JavaKaiFa.html-4fbb86cc.js" as="script"><link rel="prefetch" href="/assets/JSR303.html-b976b418.js" as="script"><link rel="prefetch" href="/assets/MinIO.html-5e3d4702.js" as="script"><link rel="prefetch" href="/assets/ShardingJDBC.html-d0f811b3.js" as="script"><link rel="prefetch" href="/assets/Swagger.html-bb111a21.js" as="script"><link rel="prefetch" href="/assets/Vuepress.html-994cf672.js" as="script"><link rel="prefetch" href="/assets/Angular.html-3115afab.js" as="script"><link rel="prefetch" href="/assets/ElementUI.html-35bc6477.js" as="script"><link rel="prefetch" href="/assets/Html-Js.html-015f1806.js" as="script"><link rel="prefetch" href="/assets/Vue-basics.html-a64846f4.js" as="script"><link rel="prefetch" href="/assets/Vue3_group.html-f53be77f.js" as="script"><link rel="prefetch" href="/assets/Vue3_option.html-19f76b9e.js" as="script"><link rel="prefetch" href="/assets/ApifoxAPIceshi.html-19cd8153.js" as="script"><link rel="prefetch" href="/assets/PDManeryuanshujianmo.html-f6fa9d9e.js" as="script"><link rel="prefetch" href="/assets/OCRwenzishibie.html-11fc474d.js" as="script"><link rel="prefetch" href="/assets/EasyExcelbiaogeku.html-30777927.js" as="script"><link rel="prefetch" href="/assets/Javadaimashengchengqi.html-cf566ce0.js" as="script"><link rel="prefetch" href="/assets/JDKshuangbanben.html-1f259d3b.js" as="script"><link rel="prefetch" href="/assets/JSR303canshuxiaoyan.html-78322130.js" as="script"><link rel="prefetch" href="/assets/Mail  youjian.html-7e3a0f69.js" as="script"><link rel="prefetch" href="/assets/MyBatisPlusxiangjie.html-0168c152.js" as="script"><link rel="prefetch" href="/assets/MySQLzhucongfuzhi.html-7a4739e8.js" as="script"><link rel="prefetch" href="/assets/Redis-API.html-f488940c.js" as="script"><link rel="prefetch" href="/assets/SpringBootshiwu.html-c07a3864.js" as="script"><link rel="prefetch" href="/assets/SpringBootduxiefenli.html-f0993780.js" as="script"><link rel="prefetch" href="/assets/Springguolvqihelanjieqi.html-78feb321.js" as="script"><link rel="prefetch" href="/assets/WebSocket.html-caecf367.js" as="script"><link rel="prefetch" href="/assets/quanjuyichang-JSR303.html-add01eff.js" as="script"><link rel="prefetch" href="/assets/Docker.html-14746447.js" as="script"><link rel="prefetch" href="/assets/Dockeryuanchengfangwenbushu.html-7dc4f8d3.js" as="script"><link rel="prefetch" href="/assets/Nginxfanxiangdaili.html-42533685.js" as="script"><link rel="prefetch" href="/assets/Apai-SheYingOne.html-143bc574.js" as="script"><link rel="prefetch" href="/assets/Apai-Year.html-b713587f.js" as="script"><link rel="prefetch" href="/assets/My2305.html-b224c5e2.js" as="script"><link rel="prefetch" href="/assets/My2306.html-94838726.js" as="script"><link rel="prefetch" href="/assets/My2307.html-df2118c4.js" as="script"><link rel="prefetch" href="/assets/My2308.html-396c79bc.js" as="script"><link rel="prefetch" href="/assets/My2309.html-1ebdc4bb.js" as="script"><link rel="prefetch" href="/assets/My2310.html-d4ffbd04.js" as="script"><link rel="prefetch" href="/assets/My2311.html-30f23133.js" as="script"><link rel="prefetch" href="/assets/My2312.html-2da62191.js" as="script"><link rel="prefetch" href="/assets/Yi-HuBei.html-90d02bf7.js" as="script"><link rel="prefetch" href="/assets/Yi-ZhuHai.html-e202f6fb.js" as="script"><link rel="prefetch" href="/assets/Apache ECharts tubiao.html-6d4a4703.js" as="script"><link rel="prefetch" href="/assets/Vue3 zuheshi API.html-9fe2887f.js" as="script"><link rel="prefetch" href="/assets/Vue3 xuanxiangshi API.html-d584c181.js" as="script"><link rel="prefetch" href="/assets/Vue3-i18n-guojihuachajian.html-16f6e650.js" as="script"><link rel="prefetch" href="/assets/Batpichulijiaoben.html-307223b0.js" as="script"><link rel="prefetch" href="/assets/Gitgongzuoliu.html-fa6e129f.js" as="script"><link rel="prefetch" href="/assets/Typoratuchuang.html-22c57156.js" as="script"><link rel="prefetch" href="/assets/Vuepress.html-df146bdb.js" as="script"><link rel="prefetch" href="/assets/My2401.html-49f6440f.js" as="script"><link rel="prefetch" href="/assets/My2402.html-950d4e85.js" as="script"><link rel="prefetch" href="/assets/shenhai-0509.html-2007281b.js" as="script"><link rel="prefetch" href="/assets/zhuhaixing.html-17db8380.js" as="script"><link rel="prefetch" href="/assets/404.html-f9875e7b.js" as="script"><link rel="prefetch" href="/assets/index.html-40bced6f.js" as="script"><link rel="prefetch" href="/assets/index.html-3c78780e.js" as="script"><link rel="prefetch" href="/assets/index.html-ef51ba1b.js" as="script"><link rel="prefetch" href="/assets/index.html-bdec80a5.js" as="script"><link rel="prefetch" href="/assets/index.html-3b5427f8.js" as="script"><link rel="prefetch" href="/assets/index.html-cbd49540.js" as="script"><link rel="prefetch" href="/assets/index.html-b0b97c81.js" as="script"><link rel="prefetch" href="/assets/index.html-2793d245.js" as="script"><link rel="prefetch" href="/assets/index.html-71d9a5d9.js" as="script"><link rel="prefetch" href="/assets/index.html-4e7d77cd.js" as="script"><link rel="prefetch" href="/assets/index.html-aeace11a.js" as="script"><link rel="prefetch" href="/assets/index.html-c62ed802.js" as="script"><link rel="prefetch" href="/assets/index.html-e640d31f.js" as="script"><link rel="prefetch" href="/assets/index.html-48e1c605.js" as="script"><link rel="prefetch" href="/assets/index.html-385dcb56.js" as="script"><link rel="prefetch" href="/assets/index.html-1bb1a523.js" as="script"><link rel="prefetch" href="/assets/index.html-1ed80e8d.js" as="script"><link rel="prefetch" href="/assets/index.html-2c154a45.js" as="script"><link rel="prefetch" href="/assets/index.html-3e93d436.js" as="script"><link rel="prefetch" href="/assets/index.html-2a93e2c9.js" as="script"><link rel="prefetch" href="/assets/index.html-cff07ba3.js" as="script"><link rel="prefetch" href="/assets/index.html-7ec32a34.js" as="script"><link rel="prefetch" href="/assets/index.html-ddb40108.js" as="script"><link rel="prefetch" href="/assets/index.html-40ab6c4f.js" as="script"><link rel="prefetch" href="/assets/index.html-47e4ee8b.js" as="script"><link rel="prefetch" href="/assets/index.html-c15250e1.js" as="script"><link rel="prefetch" href="/assets/index.html-fb2ea2e4.js" as="script"><link rel="prefetch" href="/assets/index.html-d7e5408a.js" as="script"><link rel="prefetch" href="/assets/index.html-a38055d0.js" as="script"><link rel="prefetch" href="/assets/index.html-be4e50cb.js" as="script"><link rel="prefetch" href="/assets/index.html-660e4bef.js" as="script"><link rel="prefetch" href="/assets/index.html-98aa61ea.js" as="script"><link rel="prefetch" href="/assets/index.html-a6b7472f.js" as="script"><link rel="prefetch" href="/assets/index.html-ab78917a.js" as="script"><link rel="prefetch" href="/assets/biaoqian-fenlei-moban.html-f2c6c309.js" as="script"><link rel="prefetch" href="/assets/MuBan-Apai.html-5714876d.js" as="script"><link rel="prefetch" href="/assets/guide.html-9a89b22b.js" as="script"><link rel="prefetch" href="/assets/Lu-aboutMe.html-f8203e0a.js" as="script"><link rel="prefetch" href="/assets/kaishi.html-4ff9d0f3.js" as="script"><link rel="prefetch" href="/assets/Hobby-SheYing.html-e1ab7a00.js" as="script"><link rel="prefetch" href="/assets/Lu-aboutMe.html-4b735204.js" as="script"><link rel="prefetch" href="/assets/Work-MaYun.html-a185f330.js" as="script"><link rel="prefetch" href="/assets/JavaAPI.html-f75cbb54.js" as="script"><link rel="prefetch" href="/assets/JavaBiKeng04.html-d2fc755d.js" as="script"><link rel="prefetch" href="/assets/JavaGongNeng03.html-c51a3060.js" as="script"><link rel="prefetch" href="/assets/JavaJinJie02.html-e5a66660.js" as="script"><link rel="prefetch" href="/assets/JavaMyUtil.html-6e16ee98.js" as="script"><link rel="prefetch" href="/assets/MyBatisPlus.html-1cafeb7e.js" as="script"><link rel="prefetch" href="/assets/MySql.html-5adc8c86.js" as="script"><link rel="prefetch" href="/assets/MySqlFunction.html-2c432c8c.js" as="script"><link rel="prefetch" href="/assets/RabbitMQ.html-d771200f.js" as="script"><link rel="prefetch" href="/assets/Redis.html-aa5c160a.js" as="script"><link rel="prefetch" href="/assets/ShiWuAffair.html-ce7fc825.js" as="script"><link rel="prefetch" href="/assets/Spring.html-3d622ed7.js" as="script"><link rel="prefetch" href="/assets/SpringConfig.html-6fe667f9.js" as="script"><link rel="prefetch" href="/assets/SpringPeiZhi.html-96b777da.js" as="script"><link rel="prefetch" href="/assets/SpringSecurity.html-fe792e2f.js" as="script"><link rel="prefetch" href="/assets/WebSocket.html-7fd7be86.js" as="script"><link rel="prefetch" href="/assets/DockerCompose.html-f6ef44c4.js" as="script"><link rel="prefetch" href="/assets/Linux.html-a1058183.js" as="script"><link rel="prefetch" href="/assets/Nginx.html-bf694d87.js" as="script"><link rel="prefetch" href="/assets/RabbitMQ_COPY.html-1e53d902.js" as="script"><link rel="prefetch" href="/assets/Redis_COPY.html-ef853ef3.js" as="script"><link rel="prefetch" href="/assets/Redis_CRUD.html-7a4bb7d5.js" as="script"><link rel="prefetch" href="/assets/BatJiaoBen.html-20ec59d7.js" as="script"><link rel="prefetch" href="/assets/DmShengChen.html-92a2db1f.js" as="script"><link rel="prefetch" href="/assets/EasyExcel.html-ac2c3493.js" as="script"><link rel="prefetch" href="/assets/GitLu.html-27823973.js" as="script"><link rel="prefetch" href="/assets/JavaKaiFa.html-ff11bb84.js" as="script"><link rel="prefetch" href="/assets/JSR303.html-0c745945.js" as="script"><link rel="prefetch" href="/assets/MinIO.html-958125dd.js" as="script"><link rel="prefetch" href="/assets/ShardingJDBC.html-ce0afe07.js" as="script"><link rel="prefetch" href="/assets/Swagger.html-9c9fb3be.js" as="script"><link rel="prefetch" href="/assets/Vuepress.html-4e07419a.js" as="script"><link rel="prefetch" href="/assets/Angular.html-3e716bd5.js" as="script"><link rel="prefetch" href="/assets/ElementUI.html-70835a6c.js" as="script"><link rel="prefetch" href="/assets/Html-Js.html-848bb521.js" as="script"><link rel="prefetch" href="/assets/Vue-basics.html-772005d8.js" as="script"><link rel="prefetch" href="/assets/Vue3_group.html-69369e84.js" as="script"><link rel="prefetch" href="/assets/Vue3_option.html-37ac05d4.js" as="script"><link rel="prefetch" href="/assets/ApifoxAPIceshi.html-0bcb1468.js" as="script"><link rel="prefetch" href="/assets/PDManeryuanshujianmo.html-4c377e02.js" as="script"><link rel="prefetch" href="/assets/OCRwenzishibie.html-b4248616.js" as="script"><link rel="prefetch" href="/assets/EasyExcelbiaogeku.html-511b0f0b.js" as="script"><link rel="prefetch" href="/assets/Javadaimashengchengqi.html-33991c95.js" as="script"><link rel="prefetch" href="/assets/JDKshuangbanben.html-8bba14d4.js" as="script"><link rel="prefetch" href="/assets/JSR303canshuxiaoyan.html-7d12c0ef.js" as="script"><link rel="prefetch" href="/assets/Mail  youjian.html-d520132f.js" as="script"><link rel="prefetch" href="/assets/MyBatisPlusxiangjie.html-94d1940a.js" as="script"><link rel="prefetch" href="/assets/MySQLzhucongfuzhi.html-bf156f04.js" as="script"><link rel="prefetch" href="/assets/Redis-API.html-534cd405.js" as="script"><link rel="prefetch" href="/assets/SpringBootshiwu.html-a83407ed.js" as="script"><link rel="prefetch" href="/assets/SpringBootduxiefenli.html-e50eba32.js" as="script"><link rel="prefetch" href="/assets/Springguolvqihelanjieqi.html-b7cdfd68.js" as="script"><link rel="prefetch" href="/assets/WebSocket.html-7c2b5253.js" as="script"><link rel="prefetch" href="/assets/quanjuyichang-JSR303.html-1f70d8b7.js" as="script"><link rel="prefetch" href="/assets/Docker.html-51026828.js" as="script"><link rel="prefetch" href="/assets/Dockeryuanchengfangwenbushu.html-f42be316.js" as="script"><link rel="prefetch" href="/assets/Nginxfanxiangdaili.html-a98dc972.js" as="script"><link rel="prefetch" href="/assets/Apai-SheYingOne.html-b5b7ae7c.js" as="script"><link rel="prefetch" href="/assets/Apai-Year.html-ce260a3f.js" as="script"><link rel="prefetch" href="/assets/My2305.html-8daa1c69.js" as="script"><link rel="prefetch" href="/assets/My2306.html-893e00c1.js" as="script"><link rel="prefetch" href="/assets/My2307.html-e78450ff.js" as="script"><link rel="prefetch" href="/assets/My2308.html-0e38205b.js" as="script"><link rel="prefetch" href="/assets/My2309.html-06a48ebc.js" as="script"><link rel="prefetch" href="/assets/My2310.html-59afa2c3.js" as="script"><link rel="prefetch" href="/assets/My2311.html-b634eab1.js" as="script"><link rel="prefetch" href="/assets/My2312.html-aafaa08a.js" as="script"><link rel="prefetch" href="/assets/Yi-HuBei.html-61c8ef5d.js" as="script"><link rel="prefetch" href="/assets/Yi-ZhuHai.html-26a46f60.js" as="script"><link rel="prefetch" href="/assets/Apache ECharts tubiao.html-e9cc0012.js" as="script"><link rel="prefetch" href="/assets/Vue3 zuheshi API.html-11ae0fbc.js" as="script"><link rel="prefetch" href="/assets/Vue3 xuanxiangshi API.html-ce744458.js" as="script"><link rel="prefetch" href="/assets/Vue3-i18n-guojihuachajian.html-1fa338e8.js" as="script"><link rel="prefetch" href="/assets/Batpichulijiaoben.html-06ab27bc.js" as="script"><link rel="prefetch" href="/assets/Gitgongzuoliu.html-b1e45d5c.js" as="script"><link rel="prefetch" href="/assets/Typoratuchuang.html-cb5c9b25.js" as="script"><link rel="prefetch" href="/assets/Vuepress.html-c36453a2.js" as="script"><link rel="prefetch" href="/assets/My2401.html-9b16cb88.js" as="script"><link rel="prefetch" href="/assets/My2402.html-3ade37a1.js" as="script"><link rel="prefetch" href="/assets/shenhai-0509.html-648d7d95.js" as="script"><link rel="prefetch" href="/assets/zhuhaixing.html-7d486783.js" as="script"><link rel="prefetch" href="/assets/404.html-7c90b0cc.js" as="script"><link rel="prefetch" href="/assets/reco-valine-a0c1af1f.js" as="script">
    <link rel="preload" href="/assets/style-8a0f09c6.css" as="style"><link rel="stylesheet" href="/assets/style-8a0f09c6.css">
  </head>
  <body>
    <div id="app"><!--[--><div class="theme-container"><div class="common-wrapper show-series show-catalog"><div><header class="navbar-container"><!--[--><div class="site-brand nav-item"><img class="logo" src="/logo.png" alt="阿派 | Apai Blog"><a href="/" class="site-name can-hide">阿派 | Apai Blog</a></div><div class="nav-item navbar-links-wrapper" style=""><form class="search-box" role="search"><input type="search" autocomplete="off" spellcheck="false" value><!----></form><nav class="navbar-links"><!--[--><div class="navbar-links__item"><a href="/" class="link router-link-active" aria-label="Home"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Home<!--]--></span></span><!--[--><!--]--></a></div><div class="navbar-links__item"><a href="/categories/Java/1/" class="link" aria-label="分类组"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->分类组<!--]--></span></span><!--[--><!--]--></a></div><div class="navbar-links__item"><a href="/tags/Rests/1/" class="link" aria-label="标签组"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->标签组<!--]--></span></span><!--[--><!--]--></a></div><div class="navbar-links__item"><div class="dropdown-link"><button class="dropdown-link__title" type="button" aria-label="文档组"><span class="xicon-container left title"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->文档组<!--]--></span></span><span class="arrow down"></span></button><button class="dropdown-link--mobile__title" type="button" aria-label="文档组"><span class="title"><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->文档组<!--]--></span></span></span><span class="right arrow"></span></button><ul style="display:none;" class="dropdown-link__container"><!--[--><li class="dropdown-link__item"><a href="/docs/Web-develop/Html-Js" class="link" aria-label="Web-开发"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Web-开发<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Java-develop/JavaMyUtil" class="link" aria-label="Java-开发"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java-开发<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Linux-develop/Linux" class="link" aria-label="Linux-系统"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Linux-系统<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Rests-docs/Vuepress" class="link" aria-label="Apai-其他"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Apai-其他<!--]--></span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-links__item"><div class="dropdown-link"><button class="dropdown-link__title" type="button" aria-label="花圃里"><span class="xicon-container left title"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->花圃里<!--]--></span></span><span class="arrow down"></span></button><button class="dropdown-link--mobile__title" type="button" aria-label="花圃里"><span class="title"><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->花圃里<!--]--></span></span></span><span class="right arrow"></span></button><ul style="display:none;" class="dropdown-link__container"><!--[--><li class="dropdown-link__item"><a href="/docs/Apai-MyRecord/My-2023/My2307" class="link" aria-label="2023-花开万里"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->2023-花开万里<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Apai-MyRecord/My-2024/My2401" class="link" aria-label="2024-随心而来"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->2024-随心而来<!--]--></span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-links__item"><a href="/docs/Apai-AboutMe/Lu-aboutMe" class="link" aria-label="关于我"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->关于我<!--]--></span></span><!--[--><!--]--></a></div><!--]--></nav><span class="xicon-container btn-toggle-dark-mode btn--dark-mode"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" style="width:20px;height:20px;font-size:20px;color:inherit;"><path d="M15 2h2v3h-2z" fill="currentColor"></path><path d="M27 15h3v2h-3z" fill="currentColor"></path><path d="M15 27h2v3h-2z" fill="currentColor"></path><path d="M2 15h3v2H2z" fill="currentColor"></path><path d="M5.45 6.884l1.414-1.415l2.121 2.122l-1.414 1.414z" fill="currentColor"></path><path d="M23 7.58l2.121-2.12l1.414 1.414l-2.121 2.121z" fill="currentColor"></path><path d="M23.002 24.416l1.415-1.414l2.12 2.122l-1.413 1.414z" fill="currentColor"></path><path d="M5.47 25.13L7.59 23L9 24.42l-2.12 2.12l-1.41-1.41z" fill="currentColor"></path><path d="M16 8a8 8 0 1 0 8 8a8 8 0 0 0-8-8zm0 14a6 6 0 0 1 0-12z" fill="currentColor"></path></svg></span><span class="xicon-container btn-toggle-menus"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" style="width:20px;height:20px;font-size:20px;color:inherit;"><circle cx="16" cy="8" r="2" fill="currentColor"></circle><circle cx="16" cy="16" r="2" fill="currentColor"></circle><circle cx="16" cy="24" r="2" fill="currentColor"></circle></svg></span></div><!--]--></header><div class="mobile-menus-container"><nav class="navbar-links mobile"><!--[--><div class="navbar-links__item"><a href="/" class="link router-link-active" aria-label="Home"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Home<!--]--></span></span><!--[--><!--]--></a></div><div class="navbar-links__item"><a href="/categories/Java/1/" class="link" aria-label="分类组"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->分类组<!--]--></span></span><!--[--><!--]--></a></div><div class="navbar-links__item"><a href="/tags/Rests/1/" class="link" aria-label="标签组"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->标签组<!--]--></span></span><!--[--><!--]--></a></div><div class="navbar-links__item"><div class="dropdown-link"><button class="dropdown-link__title" type="button" aria-label="文档组"><span class="xicon-container left title"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->文档组<!--]--></span></span><span class="arrow down"></span></button><button class="dropdown-link--mobile__title" type="button" aria-label="文档组"><span class="title"><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->文档组<!--]--></span></span></span><span class="right arrow"></span></button><ul style="display:none;" class="dropdown-link__container"><!--[--><li class="dropdown-link__item"><a href="/docs/Web-develop/Html-Js" class="link" aria-label="Web-开发"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Web-开发<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Java-develop/JavaMyUtil" class="link" aria-label="Java-开发"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java-开发<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Linux-develop/Linux" class="link" aria-label="Linux-系统"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Linux-系统<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Rests-docs/Vuepress" class="link" aria-label="Apai-其他"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Apai-其他<!--]--></span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-links__item"><div class="dropdown-link"><button class="dropdown-link__title" type="button" aria-label="花圃里"><span class="xicon-container left title"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->花圃里<!--]--></span></span><span class="arrow down"></span></button><button class="dropdown-link--mobile__title" type="button" aria-label="花圃里"><span class="title"><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->花圃里<!--]--></span></span></span><span class="right arrow"></span></button><ul style="display:none;" class="dropdown-link__container"><!--[--><li class="dropdown-link__item"><a href="/docs/Apai-MyRecord/My-2023/My2307" class="link" aria-label="2023-花开万里"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->2023-花开万里<!--]--></span></span><!--[--><!--]--></a></li><li class="dropdown-link__item"><a href="/docs/Apai-MyRecord/My-2024/My2401" class="link" aria-label="2024-随心而来"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->2024-随心而来<!--]--></span></span><!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-links__item"><a href="/docs/Apai-AboutMe/Lu-aboutMe" class="link" aria-label="关于我"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->关于我<!--]--></span></span><!--[--><!--]--></a></div><!--]--></nav><div class="appearance"><span>Appearance</span><span class="xicon-container btn-toggle-dark-mode"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" style="width:20px;height:20px;font-size:20px;color:inherit;"><path d="M15 2h2v3h-2z" fill="currentColor"></path><path d="M27 15h3v2h-3z" fill="currentColor"></path><path d="M15 27h2v3h-2z" fill="currentColor"></path><path d="M2 15h3v2H2z" fill="currentColor"></path><path d="M5.45 6.884l1.414-1.415l2.121 2.122l-1.414 1.414z" fill="currentColor"></path><path d="M23 7.58l2.121-2.12l1.414 1.414l-2.121 2.121z" fill="currentColor"></path><path d="M23.002 24.416l1.415-1.414l2.12 2.122l-1.413 1.414z" fill="currentColor"></path><path d="M5.47 25.13L7.59 23L9 24.42l-2.12 2.12l-1.41-1.41z" fill="currentColor"></path><path d="M16 8a8 8 0 1 0 8 8a8 8 0 0 0-8-8zm0 14a6 6 0 0 1 0-12z" fill="currentColor"></path></svg></span></div></div><div class="series-mask"></div><aside class="series-container"><div class="site-brand"><img class="logo" src="/logo.png" alt="阿派 | Apai Blog"><a href="/" class="site-name can-hide">阿派 | Apai Blog</a></div><!--[--><!--[--><section class="series-group series-item"><h5 class="series-heading active">Java 笔记</h5><ul><li><!--[--><a href="/docs/Java-develop/JavaMyUtil.html" class="link series-item" aria-label="阿派的工具类"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->阿派的工具类<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a aria-current="page" href="/docs/Java-develop/Java-basics.html" class="router-link-active router-link-exact-active link router-link-active series-item active" aria-label="Java 基础"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java 基础<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/JavaJinJie02.html" class="link series-item" aria-label="Java 基础_进阶二"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java 基础_进阶二<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/JavaGongNeng03.html" class="link series-item" aria-label="Java 功能实现"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java 功能实现<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/JavaBiKeng04.html" class="link series-item" aria-label="Java 避坑及技巧"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java 避坑及技巧<!--]--></span></span><!--[--><!--]--></a><!--]--></li></ul></section><!--]--><!--[--><section class="series-group series-item"><h5 class="series-heading">Java 基础</h5><ul><li><!--[--><a href="/docs/Java-develop/JavaAPI.html" class="link series-item" aria-label="Java API"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java API<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/WebSocket.html" class="link series-item" aria-label="WebSocket"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->WebSocket<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/ShiWuAffair.html" class="link series-item" aria-label="Spring Boot 事务"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Spring Boot 事务<!--]--></span></span><!--[--><!--]--></a><!--]--></li></ul></section><!--]--><!--[--><section class="series-group series-item"><h5 class="series-heading">MySql 数据库</h5><ul><li><!--[--><a href="/docs/Java-develop/MySql.html" class="link series-item" aria-label="MySql 数据库"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->MySql 数据库<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/MySqlFunction.html" class="link series-item" aria-label="MySql 函数"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->MySql 函数<!--]--></span></span><!--[--><!--]--></a><!--]--></li></ul></section><!--]--><!--[--><section class="series-group series-item"><h5 class="series-heading">Java 框架</h5><ul><li><!--[--><a href="/docs/Java-develop/Spring.html" class="link series-item" aria-label="Spring_框架"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Spring_框架<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/SpringPeiZhi.html" class="link series-item" aria-label="Spring 配置详解"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Spring 配置详解<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/MyBatisPlus.html" class="link series-item" aria-label="MyBatisPlus_框架"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->MyBatisPlus_框架<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/SpringSecurity.html" class="link series-item" aria-label="SpringSecurity 安全框架"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->SpringSecurity 安全框架<!--]--></span></span><!--[--><!--]--></a><!--]--></li></ul></section><!--]--><!--[--><section class="series-group series-item"><h5 class="series-heading">微服务</h5><ul><li><!--[--><a href="/docs/Java-develop/SpringConfig.html" class="link series-item" aria-label="SpringConfig 微服务"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->SpringConfig 微服务<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/Redis.html" class="link series-item" aria-label="Redis 内存数据库"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Redis 内存数据库<!--]--></span></span><!--[--><!--]--></a><!--]--></li><li><!--[--><a href="/docs/Java-develop/RabbitMQ.html" class="link series-item" aria-label="RabbitMQ 消息队列"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->RabbitMQ 消息队列<!--]--></span></span><!--[--><!--]--></a><!--]--></li></ul></section><!--]--><!--]--></aside><!--[--><main class="page-container"><h1 class="page-title">Java 基础</h1><div class="page-info"><span class="xicon-container left"><!--[--><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" class="xicon-icon" style="width:18px;height:18px;font-size:18px;color:inherit;"><path d="M16 4a5 5 0 1 1-5 5a5 5 0 0 1 5-5m0-2a7 7 0 1 0 7 7a7 7 0 0 0-7-7z" fill="currentColor"></path><path d="M26 30h-2v-5a5 5 0 0 0-5-5h-6a5 5 0 0 0-5 5v5H6v-5a7 7 0 0 1 7-7h6a7 7 0 0 1 7 7z" fill="currentColor"></path></svg><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->LuisApai<!--]--></span></span><span class="xicon-container left"><!--[--><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" class="xicon-icon" style="width:18px;height:18px;font-size:18px;color:inherit;"><path d="M26 4h-4V2h-2v2h-8V2h-2v2H6c-1.1 0-2 .9-2 2v20c0 1.1.9 2 2 2h20c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 22H6V12h20v14zm0-16H6V6h4v2h2V6h8v2h2V6h4v4z" fill="currentColor"></path></svg><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->2023/02/15<!--]--></span></span><!----><!----><!----></div><div class="theme-reco-default-content"><div><h2 id="java-开发" tabindex="-1"><a class="header-anchor" href="#java-开发" aria-hidden="true">#</a> Java 开发</h2><h3 id="体系结构" tabindex="-1"><a class="header-anchor" href="#体系结构" aria-hidden="true">#</a> <strong>体系结构:</strong></h3><ul><li>JAVASE 为java语言的基础核心</li><li>JAVAEE 企业级项目开发</li><li>JAVAME 为移动通信设备（淘汰）</li></ul><p><strong>分类:</strong></p><ul><li>jdk：开发工具包</li><li>jre：java运行时的环境</li><li>jvm：Java虚拟机（负责Java程序的运行）</li></ul><p><strong>Java开发运行过程</strong></p><blockquote><p>使用开发工具编写java源码，之后使用编译器将源码编译成class文件，最后通过jvm将class文件进行加载并运行</p></blockquote><h3 id="标识符与关键字" tabindex="-1"><a class="header-anchor" href="#标识符与关键字" aria-hidden="true">#</a> 标识符与关键字</h3><p><strong>标识符</strong></p><blockquote><p>标识符就是名字，它的作用是用来给变量、类、方法、数组等进行命名的。</p></blockquote><p><strong>命名规则</strong></p><ul><li>可以由大小写字母,数字，_ , $</li><li>不能以数字开头</li><li>不能是java关键字</li></ul><p><strong>命名规范</strong></p><ul><li>见名知意 类:大驼峰(每个单词的首字母大写)</li><li>变量:小驼峰(第一个单词首字母小写,后面每个单词首字母大写)</li><li>常量:所有的字母都大写,每个单词之间使用_连接</li></ul><p><strong>关键字</strong></p><ul><li>Java语言中的关键字都是小写英文字母</li><li>特殊的标识符,是Java语言里赋予特定的意义</li></ul><h2 id="java-基础字段" tabindex="-1"><a class="header-anchor" href="#java-基础字段" aria-hidden="true">#</a> Java 基础字段</h2><p><strong>变量</strong>:</p><p>​ 变量是计算机内存中的一块区域 语法是由声明变量和赋值组成, ​ 变量的特点有:变量值可变,变量名不可重复.</p><p><strong>常量:</strong></p><p>​ final 数据类型 常量名 = 值; 常量的值不可变而变量的值可变.</p><h3 id="数据类型" tabindex="-1"><a class="header-anchor" href="#数据类型" aria-hidden="true">#</a> 数据类型</h3><h4 id="基本数据类型" tabindex="-1"><a class="header-anchor" href="#基本数据类型" aria-hidden="true">#</a> 基本数据类型</h4><h5 id="数值类型" tabindex="-1"><a class="header-anchor" href="#数值类型" aria-hidden="true">#</a> 数值类型</h5><blockquote><p>整数</p></blockquote><ul><li><p>byte</p></li><li><p>short</p></li><li><p>int -- 常用</p></li><li><p>long 超过int的最大取值后加L</p></li></ul><blockquote><p>小数类型</p></blockquote><ul><li><p>float 赋值需加F</p></li><li><p>double -- 常用</p></li></ul><ul><li>容器大小 byte &lt; short &lt; int &lt; long &lt; flogat &lt; double</li></ul><h5 id="字符类型" tabindex="-1"><a class="header-anchor" href="#字符类型" aria-hidden="true">#</a> 字符类型</h5><ul><li>char 只能为单个字符</li></ul><h5 id="布尔类型" tabindex="-1"><a class="header-anchor" href="#布尔类型" aria-hidden="true">#</a> 布尔类型</h5><ul><li>boolean 真（true） 假（false)</li></ul><h4 id="引用数据类型" tabindex="-1"><a class="header-anchor" href="#引用数据类型" aria-hidden="true">#</a> 引用数据类型</h4><h5 id="字符串" tabindex="-1"><a class="header-anchor" href="#字符串" aria-hidden="true">#</a> 字符串</h5><p>String</p><h4 id="数据类型的转换" tabindex="-1"><a class="header-anchor" href="#数据类型的转换" aria-hidden="true">#</a> 数据类型的转换</h4><blockquote><p>布尔类型不参加类型的转换</p></blockquote><p>自动转换: 小容器转大容器</p><p>强制转换: 大容器转小容器 会发生精度丢失 short d = (short)c; 强制转换需要转换符</p><p>多种数据类型混合运算-结果为大容器类型 如: byte short运算时为常用类型-int</p><h3 id="运算符" tabindex="-1"><a class="header-anchor" href="#运算符" aria-hidden="true">#</a> 运算符</h3><h4 id="赋值运算符" tabindex="-1"><a class="header-anchor" href="#赋值运算符" aria-hidden="true">#</a> <strong>赋值运算符:</strong></h4><blockquote><p>= 从右往左运算</p></blockquote><h4 id="算术运算符" tabindex="-1"><a class="header-anchor" href="#算术运算符" aria-hidden="true">#</a> <strong>算术运算符:</strong></h4><blockquote><p>加-减-乘-除-余 + - * / %</p><p>整数相除为整数，不会四舍五入和带小数 字符串与其他类型数据进行“ + ”运算、为拼接</p></blockquote><h4 id="比较运算符" tabindex="-1"><a class="header-anchor" href="#比较运算符" aria-hidden="true">#</a> <strong>比较运算符</strong></h4><blockquote><p>== != &gt; &lt; &gt;= &lt;= 等于-不等于-大于-小于-大于等于-小于等于</p><p>结果只能为布尔类型-true/false</p></blockquote><h4 id="逻辑运算符" tabindex="-1"><a class="header-anchor" href="#逻辑运算符" aria-hidden="true">#</a> <strong>逻辑运算符</strong></h4><blockquote><p>逻辑运算符是用来进行布尔值运算的运算符，其返回值也是布尔值</p><p>&amp;&amp;: &quot;逻辑与&quot; 两边都是true才返回true，有假则假 ll: &quot;逻辑或&quot; 两边都为false才返回false，有真则真 !: &quot;逻辑非&quot; 逻辑非(!)也叫作取反符，用来取一个布尔值相反的值</p></blockquote><h4 id="自增运算符" tabindex="-1"><a class="header-anchor" href="#自增运算符" aria-hidden="true">#</a> <strong>自增运算符</strong></h4><blockquote><p>前++: 自变量+1 先运算后输出 后++: 自变量+1 先输出后运算</p></blockquote><h4 id="复合运算符" tabindex="-1"><a class="header-anchor" href="#复合运算符" aria-hidden="true">#</a> <strong>复合运算符:</strong></h4><blockquote><p>p += 2; 相当于 p = p + 2 p -= 2; 相当于 p = p - 2 p *= 2; 相当于 p = p * 2 p %= 2; 相当于 p = p % 2 p /= 2 相当于 p = p / 2 分母不能为-0 否则会报错</p></blockquote><ul><li>运算符的优先级 在做算术运算的时候,善于使用()</li></ul><h2 id="判断-迭代循环" tabindex="-1"><a class="header-anchor" href="#判断-迭代循环" aria-hidden="true">#</a> 判断 | 迭代循环</h2><h3 id="判断-if-switch" tabindex="-1"><a class="header-anchor" href="#判断-if-switch" aria-hidden="true">#</a> 判断 if - switch</h3><h4 id="if-语句与语法" tabindex="-1"><a class="header-anchor" href="#if-语句与语法" aria-hidden="true">#</a> if 语句与语法</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">if</span> <span class="token punctuation">(</span>条件<span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    条件<span class="token number">1</span>为真时执行 <span class="token operator">|</span> <span class="token keyword">if</span>中能够进行嵌套   
<span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>条件<span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">{</span> 
    条件<span class="token number">2</span>为真时执行  <span class="token operator">--</span><span class="token operator">-</span> 可创建多个分支  
<span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>   
    条件<span class="token number">1</span>和<span class="token number">2</span>都为假时执行 <span class="token operator">--</span><span class="token operator">-</span> 可以忽略     
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote><p>if跟字符串比较全等必须使用 - 变量.equals(变量) <strong>if与switch的区别: if:可范围选择,switch:只能是全等选择</strong></p></blockquote><h4 id="switch-语法" tabindex="-1"><a class="header-anchor" href="#switch-语法" aria-hidden="true">#</a> switch-语法</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">switch</span><span class="token punctuation">(</span>表达式<span class="token punctuation">)</span><span class="token punctuation">{</span>         
	<span class="token keyword">case</span>  表达式的值<span class="token number">1</span><span class="token operator">:</span>
	<span class="token comment">// 下方为执行代码 可创建多个case</span>
    <span class="token keyword">break</span><span class="token punctuation">;</span>
	<span class="token comment">// 到此停止执行</span>
    <span class="token keyword">default</span><span class="token operator">:</span>
	<span class="token comment">// 不符合以上条件所执行的代码</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="断言" tabindex="-1"><a class="header-anchor" href="#断言" aria-hidden="true">#</a> 断言</h4><blockquote><p>断言: 相对于if判断 如果为真 下方代码正常执行 否则下方代码不会执行</p></blockquote><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220722113423720.png" alt="image-20220722113423720"></p><h3 id="循环-迭代" tabindex="-1"><a class="header-anchor" href="#循环-迭代" aria-hidden="true">#</a> 循环 迭代</h3><ul><li>break :提前结束循环</li><li>continue:结束本次话环-重新开始下一次循环</li></ul><h4 id="while-循环语法" tabindex="-1"><a class="header-anchor" href="#while-循环语法" aria-hidden="true">#</a> while 循环语法</h4><p>循环三要素:可控循环次数 1.初始值 2.循环条件 3.自变</p><blockquote><p>不知道次数使用while循环 无限循环直至不满足条件才会停止 循环次数不可控为:死循环</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">while</span><span class="token punctuation">(</span>条件<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// 满足条件则循环_输出代码    </span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="do-while循环" tabindex="-1"><a class="header-anchor" href="#do-while循环" aria-hidden="true">#</a> do_while循环</h4><p>do协行代码语句 while (表达式); 表达式为真则循环执行至为假</p><blockquote><p>while与do_while的区别while:先进行条件判断在执行do_while为先执行一次在进行条件判断是否再次执行</p></blockquote><h4 id="for-语法" tabindex="-1"><a class="header-anchor" href="#for-语法" aria-hidden="true">#</a> for-语法</h4><blockquote><p>每—组for循环里的变量名是不会相互影响且可以重复变量名</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">for</span> <span class="token punctuation">(</span>初始值<span class="token punctuation">;</span>最大值<span class="token punctuation">;</span>自增<span class="token punctuation">)</span><span class="token punctuation">{</span>
    循环语句代码
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="增强-for" tabindex="-1"><a class="header-anchor" href="#增强-for" aria-hidden="true">#</a> 增强 for</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">String</span> key <span class="token operator">:</span> set<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">//获取键的对应值</span>
    <span class="token class-name">Object</span> value <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//输出键和值的拼接</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>key <span class="token operator">+</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="foreach表达式" tabindex="-1"><a class="header-anchor" href="#foreach表达式" aria-hidden="true">#</a> forEach表达式</h4><blockquote><p>即箭头函数: 能够进行集合遍历</p></blockquote><p><strong>语法:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// list和set集合</span>
集合名 <span class="token punctuation">.</span> forEach <span class="token punctuation">(</span>变量名 <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>    输出变量名   <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token comment">// map集合		</span>
集合名 <span class="token punctuation">.</span> forEach <span class="token punctuation">(</span> <span class="token punctuation">(</span>键名<span class="token punctuation">,</span> 值名<span class="token punctuation">)</span> <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>    输出键名<span class="token punctuation">,</span>和值名   <span class="token punctuation">}</span><span class="token punctuation">)</span>
		
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>案例:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;赵日天&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;李杀神&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;王诛魔&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;刘斩仙&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
list<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>e <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> hashMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;三国演义&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;罗贯中&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;红楼梦&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;曹雪芹&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;西游记&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;吴承恩&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
hashMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;水浒传&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;施耐庵&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
hashMap<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span>k<span class="token punctuation">,</span>v<span class="token punctuation">)</span> <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>k <span class="token operator">+</span> <span class="token string">&quot;  &quot;</span> <span class="token operator">+</span> v<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="迭代器" tabindex="-1"><a class="header-anchor" href="#迭代器" aria-hidden="true">#</a> 迭代器</h4><p><strong>迭代器 语法:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 获取迭代器 类似光标执行一次往下一行,如有数据则为真-true 反值则为假-false</span>
<span class="token class-name">Iterator</span><span class="token operator">&lt;</span>集合类型<span class="token operator">&gt;</span> 迭代器名 <span class="token operator">=</span> 集合名<span class="token punctuation">.</span><span class="token function">iterator</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 使用while循环配合迭代器遍历</span>
<span class="token keyword">while</span> <span class="token punctuation">(</span>迭代器名<span class="token punctuation">.</span><span class="token function">hasNext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>         <span class="token punctuation">}</span>
<span class="token comment">// 获取对于行的数据</span>
集合类型 变量名 <span class="token operator">=</span> 迭代器名<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>案例:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">IteratorClass</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> set <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        set<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;迭&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        set<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;代&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        set<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;器&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        set<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;遍&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        set<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;历&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 迭代器遍历-  - 类似光标执行一次往下一行,如有数据则为真-true 反值则为假-false</span>
        <span class="token comment">// 1.获取迭代器</span>
        <span class="token class-name">Iterator</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> iterator <span class="token operator">=</span> set<span class="token punctuation">.</span><span class="token function">iterator</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 2.使用while循环配合迭代器遍历</span>
        <span class="token keyword">while</span> <span class="token punctuation">(</span>iterator<span class="token punctuation">.</span><span class="token function">hasNext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 3.获取对于行的数据</span>
            <span class="token class-name">String</span> next <span class="token operator">=</span> iterator<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>next<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;----------------&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 增强for循环遍历</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">String</span> z <span class="token operator">:</span> set<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="数组-方法" tabindex="-1"><a class="header-anchor" href="#数组-方法" aria-hidden="true">#</a> 数组|方法</h2><h3 id="数组" tabindex="-1"><a class="header-anchor" href="#数组" aria-hidden="true">#</a> 数组</h3><h4 id="简介" tabindex="-1"><a class="header-anchor" href="#简介" aria-hidden="true">#</a> 简介:</h4><ul><li>数组有一系列的相同类型的数据的集合</li><li>同一组数组必须是同一种数据类型</li><li>数组一旦创建长度无法改变</li><li>数组下标顺序从 0 开始 数组下标的最大值为长度减_1</li></ul><h4 id="语法" tabindex="-1"><a class="header-anchor" href="#语法" aria-hidden="true">#</a> 语法:</h4><pre><code>语法一: 定义数据类型 - 数组名 = 分配空间
double[] shuzu1 = new double[5];
shuzu1[0] = 2.0;

语法二: 定义数据类型 - 数组名 = 分配空间及储存数据
int[] shuzu = {2,3,5,8,6};
</code></pre><h4 id="api" tabindex="-1"><a class="header-anchor" href="#api" aria-hidden="true">#</a> API:</h4><ul><li><p>查看数组的长度: 数组名.length;</p></li><li><p>更改对应下标的值: 数组名[下标] = 值;</p></li><li><p>系统自动排序 - 升序: Arrays.sort(数组名);</p></li><li><p>数组的补充:</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 数组之间的赋值: 将数组b赋值给啊-b数组与a数组数据将联动</span>
    <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> a <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> b <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">88</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token comment">//将数组b赋值给啊-b数组与a数组数据将联动</span>
    a <span class="token operator">=</span> b<span class="token punctuation">;</span>

<span class="token comment">// 数组的扩容-旧数组被覆盖-超过长度的数据以0填充-复制数组给予一样的数组名(被复制的数组,新数组的长度)</span>
    <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> k <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token comment">//复制数组给予一样的数组名(被复制的数组,新数组的长度)</span>
    k <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">copyOf</span><span class="token punctuation">(</span>k<span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    数组名 <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">copyOf</span><span class="token punctuation">(</span>数组名<span class="token punctuation">,</span>数组长度<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 数组的复制-新数组名 = Arrays.copyOf(被复制数组名,数组长度);</span>
    <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> k <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token comment">//复制数组(被复制的数组,新数组的长度)</span>
    <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> l <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">copyOf</span><span class="token punctuation">(</span>k<span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></li></ul><h4 id="遍历" tabindex="-1"><a class="header-anchor" href="#遍历" aria-hidden="true">#</a> 遍历:</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code>正序遍历<span class="token operator">:</span> 使用<span class="token keyword">for</span>循环<span class="token operator">:</span>从下标_0依次输出到下标最大值<span class="token punctuation">(</span>相当于小于数组个数<span class="token punctuation">)</span>
    <span class="token comment">//从下标_0依次输出到下标最大值(相当于小于数组个数)</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> shuzu2<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>  
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>shuzu2<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
倒序遍历<span class="token operator">:</span> 使用<span class="token keyword">for</span>循环<span class="token operator">:</span>从下标最大值<span class="token punctuation">(</span>相当于数组个数减_1<span class="token punctuation">)</span>倒序输出到下标_0
    <span class="token comment">//从下标最大值(相当于数组个数减_1)倒序输出到下标_0</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> shuzu2<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&gt;=</span> <span class="token number">0</span><span class="token punctuation">;</span> i<span class="token operator">--</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>  
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>shuzu2<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="方法" tabindex="-1"><a class="header-anchor" href="#方法" aria-hidden="true">#</a> 方法</h3><h4 id="main-方法" tabindex="-1"><a class="header-anchor" href="#main-方法" aria-hidden="true">#</a> main 方法</h4><blockquote><p>一个程序的启动类</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 程序入口:</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>    <span class="token punctuation">}</span>

<span class="token comment">// 修饰符_public static</span>
<span class="token comment">// 返回值类型_void</span>
<span class="token comment">// 方法名_main</span>
<span class="token comment">// 参数_(String[] args)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="自定义方法" tabindex="-1"><a class="header-anchor" href="#自定义方法" aria-hidden="true">#</a> 自定义方法</h4><p>public static void 方法名(形数参数) { 方法的执行代码 }</p><p>程序入口里调用: 方法名(实数参数);</p><ul><li>方法的调用 - 方法之间独立</li><li>方法调用时,有形数参数在实数参数里必须赋值</li><li>方法必须添加文档注释</li></ul><h4 id="返回值" tabindex="-1"><a class="header-anchor" href="#返回值" aria-hidden="true">#</a> 返回值</h4><p>return 输出返回值的变量名; 将方法的结果返回到主方法的调用处</p><p>void - 为返回值类型-指无法输出返回值-改成输出返回值的类型即可输出</p><p><strong>分类:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 没有返回值 - 没有参数</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>     执行代码    <span class="token punctuation">}</span>
<span class="token comment">// 没有返回值 - 有参数</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">b</span><span class="token punctuation">(</span><span class="token keyword">int</span> n<span class="token punctuation">)</span> <span class="token punctuation">{</span>      执行代码       <span class="token punctuation">}</span>
<span class="token comment">// 有返回值 - 没有参数</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">int</span> <span class="token function">c</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>  <span class="token keyword">return</span> <span class="token number">10</span><span class="token punctuation">;</span>  <span class="token punctuation">}</span>
<span class="token comment">// 有返回值 - 有参数</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">int</span> <span class="token function">d</span><span class="token punctuation">(</span><span class="token keyword">int</span> m<span class="token punctuation">)</span> <span class="token punctuation">{</span>   <span class="token keyword">return</span> <span class="token number">10</span><span class="token punctuation">;</span>  <span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="方法的重载" tabindex="-1"><a class="header-anchor" href="#方法的重载" aria-hidden="true">#</a> 方法的重载:</h4><p>定义: 在一个类中,多个方法,方法名称一样,参数列表不一样(参数个数,或者数据类型不一样)</p><p><strong>注意:</strong></p><ul><li>方法重载的调用,根据调用时传入的形参个数和类型,自动选择需要调用的方法</li><li>方法的重载跟参数的名称没有关系</li></ul><h4 id="方法的可变参数" tabindex="-1"><a class="header-anchor" href="#方法的可变参数" aria-hidden="true">#</a> 方法的可变参数</h4><blockquote><p>变量数据参数过多时 - 方法参数可使用 ...变量名 代替-伪数组</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">//方法的 - 可变参数</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Case_07_kebiancanshu</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token function">name</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">6</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token comment">//	变量数据参数过多时   - 方法参数可使用 ...变量名  代替-伪数组</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">name</span><span class="token punctuation">(</span><span class="token keyword">int</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>m<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> m<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>m<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="非静态方法" tabindex="-1"><a class="header-anchor" href="#非静态方法" aria-hidden="true">#</a> 非静态方法</h4><p>定义: 非静态方法 - 去掉static - 全局方法 如: public void 方法名() { }</p><p>调用: 类名.方法名();</p><p><strong>注意:</strong></p><ul><li><p>static 的方法只能调用被static修饰的语法</p></li><li><p>非 static 的方法则是都可以调用并且能够调用项目中的任何类和任何方法</p></li></ul><h4 id="变量的作用域" tabindex="-1"><a class="header-anchor" href="#变量的作用域" aria-hidden="true">#</a> 变量的作用域</h4><p><strong>局部变量</strong></p><ul><li>在方法内部创建,只能在该方法内部使用</li><li>在使用之前必须要给初值</li></ul><p><strong>成员变量</strong></p><ul><li><p>创建在类里面,方法外面,在该类的非静态方法中都可以使用</p></li><li><p>成员变量有初始值</p></li></ul><p><strong>全局变量</strong></p><ul><li>在成员变量的前面加static,在整个项目的所有类中都可以使用通过类名.变量名访问</li></ul><blockquote><p>注∶不同的作用域之间变量名可以重,变量的使用遵循就近原则</p></blockquote><h2 id="面对对象" tabindex="-1"><a class="header-anchor" href="#面对对象" aria-hidden="true">#</a> 面对对象</h2><h3 id="类" tabindex="-1"><a class="header-anchor" href="#类" aria-hidden="true">#</a> 类</h3><blockquote><p>类: 具有相同属性的对象的集合</p></blockquote><p>组成: public class 类名 { 属性- 方法 }</p><ul><li>类的名称:类名</li><li>类的属性:特征</li><li>类的方法:对象的行为</li></ul><h3 id="对象" tabindex="-1"><a class="header-anchor" href="#对象" aria-hidden="true">#</a> 对象</h3><blockquote><p>可以存储不同类型的数据,而且下标由用户自定义这种容器叫对象.</p></blockquote><p>**语法: **</p><p>定义变量: 数据类型 变量名;</p><p>创建方法-行为: 非静态方法-不能出现static | 如: public void 方法名() { }</p><p>关联: 类名 名字 = new 类名();</p><p>赋值: 名字 . 变量名 = 赋值 | 非静态方法的调用</p><p>输出变量: system.out.println(名字.变量名);</p><p>名字.方法名(); 方法里有return 变量名;</p><h3 id="构造方法" tabindex="-1"><a class="header-anchor" href="#构造方法" aria-hidden="true">#</a> 构造方法</h3><blockquote><p>this: 当成员变量和局部变量同名时使用this区分-类(我的)</p></blockquote><p><strong>构造方法特点</strong></p><ul><li>方法名跟类名一致</li><li>一个类中如果没有写构造方法,默认有一个无参的构造方法</li><li>如果写了构造方法,会覆盖默认的无参构造方法</li><li>构造方法是在创建对象的时候自动执行</li><li>构造方法没有返回值 | 构造方法可以被重戟 | 注意参数类型一致(重载)</li></ul><h3 id="构造语法" tabindex="-1"><a class="header-anchor" href="#构造语法" aria-hidden="true">#</a> 构造语法</h3><blockquote><p>定义变量: 数据类型 变量名;</p></blockquote><ul><li>创建有参构造方法-行为</li></ul><p>​ 去掉-static和void</p><p>​ public 类名( 数据类型 当局变量名 ) { this.变量名 = 变量名 }</p><ul><li>创建无参构造方法-行为</li></ul><p>​ 去掉-static和void | public 类名( ) { }</p><p>关联并所有赋值: 类名 名字 = new 类名( 数据类型对应的赋值 );</p><p>自动创建输出 toString 方法 | 一次性输出所有值: System.out.println(名字);</p><p>输出单个变量: system.out.println(名字.变量名);</p><h3 id="封装" tabindex="-1"><a class="header-anchor" href="#封装" aria-hidden="true">#</a> 封装</h3><blockquote><p>数据是存储在对象的属性中,如果用户能直接操作对象的属性,对数据是非常不安全的为了提高程序的安全性,java引入了封装的概念</p></blockquote><p><strong>优势:</strong></p><ul><li>属性私有化(private): 被私有化的属性只能在该类的内部访问,在该类的外部,不能被访问到.提供公共的方法供外部间接操作属性</li></ul><p>私有化属性: private String 变量名; 私有化方法: private void 方法名( ) { 执行代码 } 调用: 提供公共的方法公外部间接使用</p><p>**封装语法: **</p><p>定义变量: private 数据类型 变量名;</p><p>数据输入方法: public void set变量名( 类型 变量名){ this.变量名 = 变量名 }</p><p>数据输出方法: public 数据类型 get变量名( ) { return 变量名; }</p><p>步骤: 变量名首字母必须大写</p><ul><li>关联: 类名 名字 = new 类名( );</li><li>赋值: 名字.set变量名( 值 );</li><li>名字.方法名(值); 赋值给方法的变量然后在传入分类中的变量</li><li>输出单个变量: system.out.println(名字.get变量名);</li></ul><h3 id="继承" tabindex="-1"><a class="header-anchor" href="#继承" aria-hidden="true">#</a> 继承</h3><blockquote><p>继承就是子类继承父类的特征和行为，使得子类对象（实例）具有父类的实例域和方法，或子类从父类继承方法，使得子类具有父类相同的行为</p></blockquote><p>父类 - 与子类之间 有相同部分属性和方法 | 继承与封装独立开来 - 变量不能加上-private</p><p>子类与父类继承 - extends -子类程序入口类名后面 - extends 父类名</p><p><strong>继承的特点</strong></p><ol><li>构造方法不能被继承(构造方法方法名称必须跟类名一致)</li><li>一个父类可以有多个子类，一个子类只能有一个父类</li><li>可以多重继承,也就是A继承B, B继承C</li><li>私有的属性和方法不能被继承</li></ol><p><strong>继承的优缺点</strong></p><ol><li>优点: 提高代码的复用性,降低程序的冗余度</li><li>缺点: 继承破坏了封装性,继承提高了代码的耦合度</li><li>在项目开发的时候,尽可能的实现项目功能代码的高内聚,低耦合</li></ol><h3 id="重写" tabindex="-1"><a class="header-anchor" href="#重写" aria-hidden="true">#</a> 重写</h3><p><strong>定义:</strong></p><blockquote><p>子类跟据父类的方法进行重写</p><p>重写的方法必须跟父类继承的方法结构-名称-参数-返回值类型一样</p><p>重写的方法调用时比继承的方法更有优先权</p></blockquote><p>**重写与重载之间的区别: **</p><p>位置不同:</p><ul><li>方法的重载发生在一个类中</li><li>方法的重写发生在有继承关系的子类里面</li></ul><p>写法不同:</p><ul><li>方法的重载-多个方法方法名相同,参数列表不同</li><li>方法的重写-子类重写父类的方法,方法名称和参数列表必须跟父类的方法一致</li></ul><h3 id="super-关键字" tabindex="-1"><a class="header-anchor" href="#super-关键字" aria-hidden="true">#</a> super 关键字</h3><p><strong>super 关键字作用:</strong></p><ul><li>super写在子类中,用来访问父类的属性和方法</li><li>super不能访问父类私有的属性和方法</li><li>super可以在子类的构造方法中调用父类的构造方法,而且必须写在子类构造方法的第一行</li><li>在子类构造方法的第一行,默认有super(),用来调用父类的无参构造方法</li></ul><p><strong>注意: 当创建子类对象时,父类构造方法被执行</strong> 1.子类中没有写构造方法,默认有一个无参构造方法 2.子类构造方法的第一行默认有super()用来调用父类的无参构造方法,创建对象一定会执行构造方法</p><h3 id="final-关键字" tabindex="-1"><a class="header-anchor" href="#final-关键字" aria-hidden="true">#</a> final 关键字</h3><blockquote><p>final 可以用来定义常量--常量的值不可更改</p></blockquote><ul><li><p>被final修饰的类是最终类，不能被继承 | public final class Staff { }</p></li><li><p>被final修饰的方法是最终方法，不能被重写 | public final void work() { }</p></li></ul><h3 id="抽象" tabindex="-1"><a class="header-anchor" href="#抽象" aria-hidden="true">#</a> 抽象</h3><blockquote><p>抽象类</p></blockquote><p>抽象类被 - abstract - 修饰 | 抽象类不能被 - new -对象</p><p>public abstract class Athletes { } | public abstract class 类名{ }</p><p><strong>抽象父类-可以作为模板</strong></p><ul><li>抽象父类能够继承给抽象子类,非抽象子类会被强制重写</li><li>父类 - 很抽象-不应该创建对象-只能作为父类被子类继承</li></ul><blockquote><p>抽象方法</p></blockquote><p>抽象方法没有方法体-只能被子类重写</p><p>public abstract void 方法名(); | 抽象修饰方法 - abstact</p><h3 id="接口" tabindex="-1"><a class="header-anchor" href="#接口" aria-hidden="true">#</a> 接口</h3><blockquote><p>作为父类</p></blockquote><p>端口被 - interface - 修饰 | public interface 类名 { }</p><p><strong>注意:</strong></p><ul><li>接口不能被 - new-对象 - 可使用子类new对象</li><li>接口只能录入 - 全局常量和抽象方法</li></ul><div class="language-text line-numbers-mode" data-ext="text"><pre class="language-text"><code>全局常量-public static final int name = 5;  |  会默认省略为-int name = 5;
抽象方法-public abstract void name();  |  会默认省略为-void name();
default void fun1() { 被default 修饰的方法可以不强制重写  };
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="多重实现与继承" tabindex="-1"><a class="header-anchor" href="#多重实现与继承" aria-hidden="true">#</a> 多重实现与继承</h3><p><strong>子类只能有一个父类-为继承关系 | 子类与接口之间为实现关系</strong></p><ul><li>一个类可以实现多个端口 -子类使用 - implements -实现(继承)端口</li><li>如: public class 子类名 implements 端口名{ }</li></ul><p><strong>端口与端口为继承关系</strong></p><ul><li>一个端口可以继承多个端口 -端口使用 - extends -继承端口</li><li>public interface 子类名 extends 端口1,端口2{ }</li><li>端口里的抽象方法都要强制重写</li></ul><p><strong>写法</strong></p><ul><li>先写继承(extends)父类 - 在写实现(implements)端口-多个用逗号隔开</li><li>public class 子类 extends 父类 implements 端口1,端口2{ }</li></ul><h3 id="引用数据类型转换" tabindex="-1"><a class="header-anchor" href="#引用数据类型转换" aria-hidden="true">#</a> 引用数据类型转换</h3><p>数据类型向上转型 - 自动类型转换 | 父类 &gt; 子类 数据类型向下转型 - 强制类型转换 | 需要强转转换符</p><h3 id="多态" tabindex="-1"><a class="header-anchor" href="#多态" aria-hidden="true">#</a> 多态</h3><blockquote><p>在Java里 - 多态指一个对象的多种数据类型 | 指一个对象在现实生活中扮演的多种角色形态</p></blockquote><p><strong>形成的三个必要条件:</strong></p><p>1.必须有继承或者现实关系 2.必须有方法的重写 3.必须有父类引用指向子类对象</p><p>相当于 - 子类向上转型为父类的类型 - 使用父类对象名调用方法但只能调用重写还在继承的方法,如果父类方法使用private私有化则此方法无法调用</p><h3 id="修饰符" tabindex="-1"><a class="header-anchor" href="#修饰符" aria-hidden="true">#</a> 修饰符</h3><p><strong>访问修饰符</strong></p><p>权限从大到小: public &gt; protected &gt; default &gt; private</p><p><strong>非访问修饰符</strong></p><ul><li><p>static 修饰符，用来修饰类方法和类变量。修饰的属性不会被共享</p></li><li><p>final 修饰符，用来修饰类、方法和变量，final 修饰的类不能够被继承，修饰的方法不能被继承类重新定义，修饰的变量为常量，是不可修改的。</p></li><li><p>abstract 修饰符，用来创建抽象类和抽象方法。</p></li></ul><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220723230850524.png" alt="image-20220723230850524"></p><h3 id="执行顺序" tabindex="-1"><a class="header-anchor" href="#执行顺序" aria-hidden="true">#</a> 执行顺序</h3><blockquote><p>编译 - 类加载 - 创建对象</p></blockquote><p>顺序:</p><ul><li>静态代码块 - 类加载是被执行</li><li>静态代码块在类加载时执行比在创建对象时的成员代码块和构造方法快</li><li>构造方法 - 创建对象时被执行</li><li>成员代码块 - 创建对象时被执行 | 创建两个对象时不会在次进行类加载</li><li>父子类: 先执行父类在执行子类 类加载是同时进行</li></ul><p>静态代码块 &gt; 成员代码块 &gt; 构造方法</p><h3 id="匿名对象" tabindex="-1"><a class="header-anchor" href="#匿名对象" aria-hidden="true">#</a> 匿名对象</h3><blockquote><p>匿名对象由于没有名字，只能在对象创建的时候使用 在创建后如果没有被使用,会被java的垃圾回收器回牧 可以把对象作为实参传入方法中也可以使用匿名对象直接调用方法</p></blockquote><p>直接使用 new 类名( 值 ) 作为对象名 | 使用构造方法输入数据 | 使用封装get输入数据</p><h3 id="匿名内部类" tabindex="-1"><a class="header-anchor" href="#匿名内部类" aria-hidden="true">#</a> 匿名内部类</h3><p>定义: 匿名内部类指在一个类中在定义一个没有类名的类</p><p>作用:</p><ul><li>用来创建接口或者父类的子类 - 只能使用一次</li><li>通过new来创建端口的匿名子类,同时创建子类对象</li><li>可定义他的对象名来调用内部的方法</li></ul><blockquote><p>接口名 对象名 = new 接口名(){ 创建的匿名子类及对象-重写的方法 }; 使用 - 对象名.方法名调用方法 或者不给予对象名直接在类后 .方法名 调用方法</p></blockquote><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220723231216137.png" alt="image-20220723231216137"></p><h3 id="枚举" tabindex="-1"><a class="header-anchor" href="#枚举" aria-hidden="true">#</a> 枚举</h3><blockquote><p>枚举: enum 一般用于定义常量</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">package</span> <span class="token namespace">com<span class="token punctuation">.</span>apai<span class="token punctuation">.</span>util</span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">enum</span> <span class="token class-name">MessageStatus</span> <span class="token punctuation">{</span>

    <span class="token function">UNSEND</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">&quot;未发送&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">SENDED</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">&quot;已发送&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">ROUTE_ERROR</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token string">&quot;路由失败&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token keyword">private</span> <span class="token keyword">int</span> status<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> msg<span class="token punctuation">;</span>

    <span class="token class-name">MessageStatus</span><span class="token punctuation">(</span><span class="token keyword">int</span> status<span class="token punctuation">,</span><span class="token class-name">String</span> msg<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>status <span class="token operator">=</span> status<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>msg <span class="token operator">=</span> msg<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getMsg</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> msg<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getStatus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> status<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="调用枚举字段" tabindex="-1"><a class="header-anchor" href="#调用枚举字段" aria-hidden="true">#</a> 调用枚举字段</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token class-name">MessageStatus</span><span class="token punctuation">.</span><span class="token constant">UNSEND</span><span class="token punctuation">.</span><span class="token function">getMsg</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token string">&quot;未发送&quot;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="数据类型-及-api" tabindex="-1"><a class="header-anchor" href="#数据类型-及-api" aria-hidden="true">#</a> 数据类型 及 API</h2><h3 id="object-类" tabindex="-1"><a class="header-anchor" href="#object-类" aria-hidden="true">#</a> Object - 类</h3><blockquote><p>定义:类层次结构的根类,每个类都使用 Object 作为超类,即为所有类的默认父类,所有对象（包括数组）都实现这个类的方法</p></blockquote><p><strong>Object-类及方法</strong></p><ul><li><p>equals: 判断两个对象是否相等 - 地址而不是内容 - 输出值为布尔类型</p></li><li><p>hashCode: 获取对象的哈希码值,把对象的哈希码值看作对象的内存地址 ,输出为 - int 类型</p></li><li><p>toString: 子类默认继承object类 | 子类没有重写父类的toString方法,输出则是内存地址 | 子类继承重写父类的toString方法,输出字符串加上数据的表现形式</p></li><li><p>getClass: 获取创建该对象的类路径,输出为类的位置路径</p></li><li><p>finalize: 垃圾回收器 - 无法主动创建</p></li></ul><h3 id="基本数据类型的包装类" tabindex="-1"><a class="header-anchor" href="#基本数据类型的包装类" aria-hidden="true">#</a> 基本数据类型的包装类</h3><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220723232359460.png" alt="image-20220723232359460"></p><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220723232353012.png" alt="image-20220723232353012"></p><blockquote><p>在java中所有的引用类型都可以赋 null 值，null表示空的意思</p></blockquote><p><strong>包装类 方法:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// int最大值: nteger.MAX_VALUE</span>
<span class="token comment">// int最小值: Integer.MIN_VALUE</span>

<span class="token comment">// 字符串转整数 - 字符串为阿拉伯数字 </span>
<span class="token keyword">int</span> f <span class="token operator">=</span> <span class="token class-name">Integer</span><span class="token punctuation">.</span><span class="token function">parseInt</span><span class="token punctuation">(</span>  字符串数字变量名  <span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 整数转字符串</span>
<span class="token comment">// 方法一:字符串拼接</span>
<span class="token comment">// 方法二:转换</span>
<span class="token class-name">String</span> 变量名 <span class="token operator">=</span> <span class="token class-name">Integer</span>的变量名 <span class="token punctuation">.</span> <span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 自动装箱: 自动把int类型的数字转成Integer类型,该过程自动调用valueof(int r)</span>
<span class="token keyword">int</span> r <span class="token operator">=</span> <span class="token number">9</span><span class="token punctuation">;</span>
<span class="token class-name">Integer</span> s <span class="token operator">=</span> r<span class="token punctuation">;</span>
过程<span class="token class-name">Integer</span> s <span class="token operator">=</span> <span class="token class-name">Integer</span><span class="token punctuation">.</span><span class="token function">valueof</span><span class="token punctuation">(</span>r<span class="token punctuation">)</span>
<span class="token comment">// 自动拆箱: 自动把Integer类型的数字转成int类型,该过程自动调用intValue()</span>
<span class="token class-name">Integer</span> t <span class="token operator">=</span> <span class="token number">16</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> h <span class="token operator">=</span> t<span class="token punctuation">;</span> 
过程<span class="token keyword">int</span> h <span class="token operator">=</span> t<span class="token punctuation">.</span><span class="token function">intValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="string-常用-api" tabindex="-1"><a class="header-anchor" href="#string-常用-api" aria-hidden="true">#</a> String 常用 API</h3><h4 id="获取方法" tabindex="-1"><a class="header-anchor" href="#获取方法" aria-hidden="true">#</a> 获取方法</h4><p>**语法: **</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 获取长度 - 类型为数值类型 该长度为字符串里每一个字符的和</span>
<span class="token keyword">int</span> 变量名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">length</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 获取指定位置的字符 类型为字符类型 字符串中的每个字符都有下标,下标从0开始</span>
<span class="token keyword">char</span> 变量名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">charAt</span><span class="token punctuation">(</span>  下标  <span class="token punctuation">)</span>
<span class="token comment">// 获取指定字符首次出现的位置下标 类型为数值类型- 字符串用双引号</span>
变量名 <span class="token punctuation">.</span> <span class="token function">indexOf</span><span class="token punctuation">(</span>  指定字符  <span class="token punctuation">)</span>
<span class="token comment">// 获取指定字符最后一次出现的位置的下标</span>
变量名 <span class="token punctuation">.</span> <span class="token function">lastIndexOf</span><span class="token punctuation">(</span>  指定字符  <span class="token punctuation">)</span>		
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>**案例: **</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token class-name">String</span> a <span class="token operator">=</span> <span class="token string">&quot;work&quot;</span><span class="token punctuation">;</span>
<span class="token comment">// 获取方法</span>
<span class="token comment">// 1、获取长度 - 类型为数值类型</span>
<span class="token keyword">int</span> b <span class="token operator">=</span> a<span class="token punctuation">.</span><span class="token function">length</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 2.获取指定下标位置的字符(字符串中的每个字符都有下标,下标从0开始)</span>
<span class="token comment">// 类型为字符类型</span>
<span class="token keyword">char</span> c <span class="token operator">=</span> a<span class="token punctuation">.</span><span class="token function">charAt</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 3.获取指定字符首次出现的下标 - 类型为数值类型- 字符串用双引号</span>
<span class="token keyword">int</span> d <span class="token operator">=</span> a<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token string">&quot;k&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="判断方法-布尔" tabindex="-1"><a class="header-anchor" href="#判断方法-布尔" aria-hidden="true">#</a> 判断方法 - 布尔</h4><p><em><em>语法</em>:</em>**</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 判断两个字符串值是否相等 equals--String重写了Object类的equals方法,不再比较内存地址,而是比较值是否相等</span>
<span class="token keyword">boolean</span> 变量名 <span class="token operator">=</span> <span class="token string">&quot;值相等&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">&quot;值相等&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 测试此字符串是否以指定的后缀结束</span>
变量名 <span class="token punctuation">.</span> <span class="token function">endsWith</span><span class="token punctuation">(</span>  指定内容  <span class="token punctuation">)</span>
<span class="token comment">// 字符串长度是否为0 空位真-不空位假 | 可使用长度判断</span>
变量名 <span class="token punctuation">.</span> <span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 是否包含指定值 - 值为连续的</span>
变量名 <span class="token punctuation">.</span> <span class="token function">contains</span><span class="token punctuation">(</span>  指定值  <span class="token punctuation">)</span>
<span class="token comment">// 忽略大小写是否相等</span>
变量名<span class="token number">1</span> <span class="token punctuation">.</span> <span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span>  变量名<span class="token number">2</span>  <span class="token punctuation">)</span>
<span class="token comment">// 测试此字符串是否以指定的前缀开始</span>
变量名 <span class="token punctuation">.</span> <span class="token function">startsWith</span><span class="token punctuation">(</span>  指定值  <span class="token punctuation">)</span>	
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>案例:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 判断方法 - 类型为布尔</span>
<span class="token comment">// 1.equals--String重写了Object类的equals方法,不再比较内存地址,而是比较值是否相等</span>
<span class="token string">&quot;值相等&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">&quot;值相等&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;值相等&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">&quot;值相等&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">String</span> s2 <span class="token operator">=</span> <span class="token string">&quot;www.woniuxy.com&quot;</span><span class="token punctuation">;</span>
<span class="token comment">// 2.判断字符串是否以指定的后缀结束</span>
<span class="token keyword">boolean</span> e <span class="token operator">=</span> s2<span class="token punctuation">.</span><span class="token function">endsWith</span><span class="token punctuation">(</span><span class="token string">&quot;om&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 3.判断字符串是否为空--判断长度</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>s2<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//空位真 , 不空位假</span>

<span class="token keyword">int</span> f <span class="token operator">=</span> s2<span class="token punctuation">.</span><span class="token function">length</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//---可使用长度判断</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>f <span class="token operator">==</span> <span class="token number">0</span> <span class="token operator">?</span> <span class="token string">&quot;字符串为空&quot;</span><span class="token operator">:</span><span class="token string">&quot;字符串不为空&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//三元运算符 - 真则 输出左边 假则输出右边</span>
<span class="token comment">// 4.判断字符串是否包含指定的值 - 值为连续的</span>
<span class="token keyword">boolean</span> g <span class="token operator">=</span> s2<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token string">&quot;xy&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>g<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 5.比较两个字符串是否相等,并忽略大小写</span>
<span class="token class-name">String</span> h <span class="token operator">=</span> <span class="token string">&quot;WWW.woniuXY.com&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">boolean</span> y <span class="token operator">=</span> h<span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span>s2<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 6.判断字符串是否以指定的内容开头</span>
<span class="token keyword">boolean</span> m <span class="token operator">=</span> s2<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&quot;ww&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>m<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="转换方法" tabindex="-1"><a class="header-anchor" href="#转换方法" aria-hidden="true">#</a> 转换方法</h4><p><strong>语法:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 小写转大写</span>
变量名 <span class="token punctuation">.</span> <span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 大写转小写</span>
变量名 <span class="token punctuation">.</span> <span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 将字符串转换为字符数组 将字符串里的每一个字符转成一组</span>
<span class="token keyword">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span> 数组名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">toCharArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 将字符数组转为字符串</span>
<span class="token class-name">String</span> 变量名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span> 数组名 <span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>案例:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">//转换</span>
<span class="token class-name">String</span> r <span class="token operator">=</span> <span class="token string">&quot;transition&quot;</span><span class="token punctuation">;</span>
<span class="token comment">//小写转换大写</span>
<span class="token class-name">String</span> a <span class="token operator">=</span> r<span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//大写转换小写</span>
<span class="token class-name">String</span> b <span class="token operator">=</span> a<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//字符串转换数组</span>
<span class="token keyword">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span> shu <span class="token operator">=</span> r<span class="token punctuation">.</span><span class="token function">toCharArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> shu<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">//数组遍历</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>shu<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">//数组转换字符串</span>
<span class="token class-name">String</span> c <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span>shu<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="其他方法" tabindex="-1"><a class="header-anchor" href="#其他方法" aria-hidden="true">#</a> 其他方法</h4><p><strong>语法:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 替换 使用指定的值替换替换此字符串所有匹配的字符</span>
字符串变量名 <span class="token punctuation">.</span> <span class="token function">replace</span><span class="token punctuation">(</span>  被替换内容  <span class="token punctuation">,</span> 替换内容  <span class="token punctuation">)</span>
<span class="token comment">// 切割 根据指定字符将字符串切割为数组 切割转数组时第一个被切则它前面为一组(空组)-最后有一个则没有分组</span>
<span class="token comment">// 注意 无法切割点 &#39; . &#39;  需要转义  &#39;  \\.  &#39;</span>
<span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> 数组名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">split</span><span class="token punctuation">(</span>  切割值  <span class="token punctuation">)</span>
<span class="token comment">// 截取 从指定位置截取到最后 </span>
<span class="token class-name">String</span> 新变量名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">substring</span><span class="token punctuation">(</span>  截取的下标包含  <span class="token punctuation">)</span>
<span class="token comment">// 截取指定长度的字符串 前下标包含,后下标不包含</span>
<span class="token class-name">String</span> 新变量名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">substring</span><span class="token punctuation">(</span>前下标 <span class="token punctuation">,</span> 后下标<span class="token punctuation">)</span>
<span class="token comment">// 去除字符串首尾空格 去除所有空格 - 可使將空格 &quot; &quot; 替換 &quot;&quot; 空字符串</span>
变量名 <span class="token punctuation">.</span> <span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>案例:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">//其他方法</span>
<span class="token class-name">String</span> a <span class="token operator">=</span> <span class="token string">&quot;wnwewrwp&quot;</span><span class="token punctuation">;</span>
<span class="token comment">//替换 - 将指定内容替换成其他 - 指定内容将被全部替换</span>
<span class="token class-name">String</span> b <span class="token operator">=</span> a<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token string">&quot;w&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;m&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">//其他方法</span>
<span class="token class-name">String</span> a <span class="token operator">=</span> <span class="token string">&quot;wnwewrwp&quot;</span><span class="token punctuation">;</span>
<span class="token comment">//切割 - 将字符串切割成数组 - &quot;*&quot;和&quot;.&quot;无法被切割</span>
<span class="token comment">//切割转数组时第一个被切则它前面为一组(空组)-最后有一个则没有分组</span>
<span class="token class-name">String</span> c <span class="token operator">=</span> <span class="token string">&quot;a-v-w-r-f-s&quot;</span><span class="token punctuation">;</span>
<span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> d <span class="token operator">=</span> c<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&quot;-&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> d<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>d<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token class-name">String</span> a <span class="token operator">=</span> <span class="token string">&quot;wnwewrwp&quot;</span><span class="token punctuation">;</span>

<span class="token comment">//截取 - 前下标包含,后下标不包含</span>
<span class="token comment">//从指定下标截取到末尾</span>
<span class="token class-name">String</span> f <span class="token operator">=</span> a<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>f<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//截取 - 前下标包含,后下标不包含</span>
<span class="token class-name">String</span> a <span class="token operator">=</span> <span class="token string">&quot;wnwewrwp&quot;</span><span class="token punctuation">;</span>
<span class="token comment">//截取指定的下标区间 - 前下标包含,后下标不包含</span>
<span class="token class-name">String</span> t <span class="token operator">=</span> a<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">//去除首尾的空格</span>
<span class="token class-name">String</span> g<span class="token operator">=</span> <span class="token string">&quot;  前  后     &quot;</span><span class="token punctuation">;</span>
<span class="token class-name">String</span> p <span class="token operator">=</span> g<span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>p<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//去除所有空格 - 可使將空格替換 &quot;&quot; 空字符串</span>
<span class="token class-name">String</span>  n <span class="token operator">=</span> g<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token string">&quot; &quot;</span><span class="token punctuation">,</span><span class="token string">&quot;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="arrays-数组" tabindex="-1"><a class="header-anchor" href="#arrays-数组" aria-hidden="true">#</a> Arrays | 数组</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 数组复制(扩容)</span>
<span class="token keyword">int</span><span class="token punctuation">[</span> <span class="token punctuation">]</span> 新数组名 <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">copyOf</span><span class="token punctuation">(</span>  数组名 <span class="token punctuation">,</span> 新数组长度  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 数组排序--升序排序</span>
<span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span>  数组名  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 数组查找-使用二分法去数组中查找元素,数组必须是升序的,结果是元素在数组中的下标,没找到结果为负</span>
<span class="token keyword">int</span> 下标的变量名 <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">binarySearch</span><span class="token punctuation">(</span>    数组名 <span class="token punctuation">,</span>  查找的数值   <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 数组转字符串 直接输出数组输出的是数组的内存地址 返回指定数组内容的字符串表示形式。</span>
<span class="token class-name">String</span>  变量名  <span class="token operator">=</span> <span class="token class-name">Arrays</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span>  数组名  <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220723234023169.png" alt="image-20220723234023169"></p><h3 id="math-数学类" tabindex="-1"><a class="header-anchor" href="#math-数学类" aria-hidden="true">#</a> Math | 数学类</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// PI - 圆周率</span>
<span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token constant">PI</span> 
<span class="token comment">// 取绝对值--负数的绝对值是正数,正数的绝对值是它本身</span>
<span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span> 正负数值 <span class="token punctuation">)</span>
    
<span class="token comment">// 向上取整 - Math.ceil( 数值 )</span>
<span class="token comment">// 向下取整 - Math.floor( 数值 )</span>
<span class="token comment">// 四舍五入 - Math.round( 数值 )</span>
    
<span class="token comment">// 随机数生成</span>
<span class="token number">0</span> <span class="token operator">&lt;=</span> <span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">&lt;</span> <span class="token number">1</span>
<span class="token comment">// 生成1-10之间的整数 - 强制转换且注意顺序</span>
<span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">10</span><span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span>
<span class="token comment">// 求m的n次方</span>
<span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span> 数值  <span class="token punctuation">,</span>  n次方 <span class="token punctuation">)</span>
    
<span class="token comment">// 保留小数点后两位</span>
<span class="token keyword">double</span> f <span class="token operator">=</span> <span class="token number">111231.5585</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">&quot;%.2f&quot;</span><span class="token punctuation">,</span> f<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220723234242193.png" alt="image-20220723234242193"></p><h3 id="buffer-builder-字符串" tabindex="-1"><a class="header-anchor" href="#buffer-builder-字符串" aria-hidden="true">#</a> Buffer/Builder | 字符串</h3><blockquote><p>StringBuilder和StringBuffer语法一致,优先使用StringBuffer效率高 | 当程序多次使用string字符串拼接会造成卡顿</p></blockquote><ul><li>@dexcription:所有的字符串字面值都是String类的对象,同时也是常量</li><li>字符串拼接一定会创建新的字符串对象,但是对象的创建是一个非常消耗内存资源,非常耗时的操作</li><li>为了解决字符串拼接会创建新对象的问题,java引入了新的类StringBuffer和StringBuilder</li><li>String是不可变长度字符串</li><li>StringBuffer是可变长度字符串</li><li>StringBuilder是可变长度字符串</li></ul><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 创建StringBuffer对象 - 可变长度字符串</span>
	<span class="token class-name">StringBuffer</span> 变量名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 拼接且不会产生新对象 可多次拼接</span>
	变量名<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>  拼接的string变量名  <span class="token punctuation">)</span><span class="token punctuation">;</span>
		
<span class="token comment">// StringBuffer 转 string</span>
	<span class="token class-name">String</span> 变量名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 字符串的反转 - 倒过来</span>
	<span class="token class-name">StringBuffer</span> 变量名 <span class="token operator">=</span> 变量名 <span class="token punctuation">.</span> <span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 字符串转StringBuffer</span>
	<span class="token class-name">StringBuffer</span> 变量名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span> <span class="token string">&quot;内容&quot;</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token class-name">String</span> a <span class="token operator">=</span> <span class="token string">&quot;字符串&quot;</span><span class="token punctuation">;</span>
    <span class="token class-name">String</span> b <span class="token operator">=</span> <span class="token string">&quot;拼&quot;</span><span class="token punctuation">;</span>
    <span class="token class-name">String</span> c <span class="token operator">=</span> <span class="token string">&quot;接&quot;</span><span class="token punctuation">;</span>
    <span class="token comment">//当程序多次使用字符串拼接会造成卡顿</span>
    <span class="token class-name">String</span> d <span class="token operator">=</span> a <span class="token operator">+</span> b <span class="token operator">+</span> c<span class="token punctuation">;</span> 
    <span class="token comment">//创建StringBuffer对象 - 可变长度字符串</span>
    <span class="token class-name">StringBuffer</span> w <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//字符串拼接且不会产生新对象</span>
    w<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
    w<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
    w<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>w<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//StringBuffer 转 string</span>
    <span class="token class-name">String</span> r <span class="token operator">=</span> w<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>r<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//字符串的反转 - 倒过来</span>
    <span class="token class-name">StringBuffer</span> t <span class="token operator">=</span> w<span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//字符串转StringBuffer</span>
    <span class="token class-name">StringBuffer</span> y <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span><span class="token string">&quot;字符串拼接&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="date-时间" tabindex="-1"><a class="header-anchor" href="#date-时间" aria-hidden="true">#</a> Date | 时间</h3><blockquote><p>时间单位 导包: import java.util.Date;</p></blockquote><p>1y = 365d; | 1d = 24h; | 1h = 6eM; | 1M = 60s; | 1s = 1000ms;</p><blockquote><p>时间原点: 会根据电脑地方时区矫正</p></blockquote><ul><li>把1970年1月1日0时0分O秒作为时间原点(格林威治时区)</li><li>把1970年1月1日8时0分O秒作为时间原点(东八区)</li></ul><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 获取当前时间并储存</span>
<span class="token class-name">Date</span> 时间变量名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 获取时间原点带现在时间的毫秒数 数据过大 - 使用long类型</span>
<span class="token keyword">long</span> 变量名 <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 在时间原点上增加毫秒数</span>
<span class="token class-name">Date</span> m <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span>  毫秒数  <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="日期格式化" tabindex="-1"><a class="header-anchor" href="#日期格式化" aria-hidden="true">#</a> 日期格式化</h4><p>年: yyyy | 月: MM | 日: dd | 时: hh | 分: mm | 秒: ss</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 定义格式</span>
<span class="token class-name">String</span> 变量名 <span class="token operator">=</span> <span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">;</span>
<span class="token comment">// 创建日期格式转换工具</span>
<span class="token comment">// 导包: import java.text.SimpleDateFormat;</span>
<span class="token class-name">SimpleDateFormat</span> 工具变量名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span>格式变量名<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 日期转字符</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>  工具变量名 <span class="token punctuation">.</span> <span class="token function">format</span><span class="token punctuation">(</span>  时间变量名  <span class="token punctuation">)</span>  <span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token comment">// 字符串转日期 格式与定义格式一致</span>
<span class="token comment">// 导包: import java.text.ParseException; </span>
<span class="token class-name">String</span> 日期变量名<span class="token operator">=</span> <span class="token string">&quot;2023-01-01 00:00:00&quot;</span><span class="token punctuation">;</span>
<span class="token class-name">Date</span> 变量名 <span class="token operator">=</span> sdf<span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>  日期变量名  <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote><p><strong>将时间按格式转换字符串</strong></p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 时间格式 --&gt; 年: yyyy 月: MM 日: dd 时: hh 分: mm 秒: ss</span>

<span class="token comment">// 获取当当前时间并按自定义格式转换字符串</span>
<span class="token comment">// 获取当前时间</span>
<span class="token class-name">Date</span> date <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 定义格式</span>
<span class="token class-name">String</span> geshi <span class="token operator">=</span> <span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">;</span>
<span class="token comment">// 创建日期格式转换工具</span>
<span class="token class-name">SimpleDateFormat</span> sdf <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span>geshi<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 将当前时间转换自定义格式字符串</span>
<span class="token class-name">String</span> datetime <span class="token operator">=</span> sdf<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>date<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">String</span> datetime <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span><span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote><p>时间计算</p></blockquote><p>天: 相差的毫秒数 / 1000(秒) / 60(分) / 60(时) / 24(天)</p><p>时: 相差的毫秒数 / 1000(秒) / 60(分) / 60(时) %余 24(天) 小时 / 24 余下的是不足一天的小时</p><p>分: (相差的秒(相差的毫秒数 / 1000) - 满足天的秒 - 满足小时的分) /60 剩下的就是不足一个小时的秒 / 60 为不足一小时的分</p><p>秒: 相差的秒(相差的毫秒数 / 1000) - 满足天的秒 - 满足小时的分 - 满足一分的秒 剩下就是不足一分的秒</p><h4 id="date-类型" tabindex="-1"><a class="header-anchor" href="#date-类型" aria-hidden="true">#</a> Date 类型</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// Date --&gt; string </span>
<span class="token class-name">String</span> datetime <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span><span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// string --&gt; date</span>
<span class="token class-name">Date</span> date <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SimpleDateFormat</span><span class="token punctuation">(</span><span class="token string">&quot;yyyy-MM&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span><span class="token string">&quot;2022-11&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 时间偏移 上一个月 30 天</span>
<span class="token class-name">Date</span> startDate <span class="token operator">=</span> <span class="token class-name">DateUtils</span><span class="token punctuation">.</span><span class="token function">addDays</span><span class="token punctuation">(</span>date<span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="localdate" tabindex="-1"><a class="header-anchor" href="#localdate" aria-hidden="true">#</a> LocalDate</h4><p>https://blog.csdn.net/yy139926/article/details/124298574</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// LocalDate 常用Api</span>
<span class="token comment">// 获取当前日期</span>
<span class="token class-name">LocalDate</span> now <span class="token operator">=</span> <span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">LocalDateTime</span> time <span class="token operator">=</span> <span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 设置日期</span>
<span class="token class-name">LocalDate</span> localDate <span class="token operator">=</span> <span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">2019</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 获取年</span>
<span class="token keyword">int</span> year <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">getYear</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment">//结果：2019</span>
<span class="token keyword">int</span> year1 <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">ChronoField</span><span class="token punctuation">.</span><span class="token constant">YEAR</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//结果：2019</span>
<span class="token comment">// 获取月</span>
<span class="token class-name">Month</span> month <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">getMonth</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// 结果：SEPTEMBER</span>
<span class="token keyword">int</span> month1 <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">ChronoField</span><span class="token punctuation">.</span><span class="token constant">MONTH_OF_YEAR</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//结果：9</span>
<span class="token comment">// 获取日</span>
<span class="token keyword">int</span> day <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">getDayOfMonth</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">//结果：10</span>
<span class="token keyword">int</span> day1 <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">ChronoField</span><span class="token punctuation">.</span><span class="token constant">DAY_OF_MONTH</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 结果：10</span>
<span class="token comment">// 获取星期</span>
<span class="token class-name">DayOfWeek</span> dayOfWeek <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">getDayOfWeek</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">//结果：TUESDAY</span>
<span class="token keyword">int</span> dayOfWeek1 <span class="token operator">=</span> localDate<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token class-name">ChronoField</span><span class="token punctuation">.</span><span class="token constant">DAY_OF_WEEK</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//结果：2</span>

<span class="token comment">// 字符串 --&gt; LocalDate </span>
<span class="token class-name">LocalDate</span> max <span class="token operator">=</span> <span class="token class-name">LocalDate</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span><span class="token string">&quot;2022-07-05&quot;</span><span class="token punctuation">,</span><span class="token class-name">DateTimeFormatter</span><span class="token punctuation">.</span><span class="token function">ofPattern</span><span class="token punctuation">(</span><span class="token string">&quot;yyyy-MM-dd&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="localdatetime" tabindex="-1"><a class="header-anchor" href="#localdatetime" aria-hidden="true">#</a> LocalDateTime</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 获取当前日期</span>
<span class="token class-name">LocalDateTime</span> time <span class="token operator">=</span> <span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 你的时间在当前时间之后是 true</span>
你的时间<span class="token punctuation">.</span><span class="token function">isAfter</span><span class="token punctuation">(</span><span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token comment">// 你的时间在当前时间之前是 true</span>
你的时间<span class="token punctuation">.</span><span class="token function">isBefore</span><span class="token punctuation">(</span><span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    
<span class="token comment">// LocalDateTime --&gt; 字符串</span>
<span class="token class-name">String</span> dateStr <span class="token operator">=</span> <span class="token class-name">DateTimeFormatter</span><span class="token punctuation">.</span><span class="token function">ofPattern</span><span class="token punctuation">(</span><span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 字符串 --&gt; LocalDateTime </span>
<span class="token class-name">LocalDateTime</span> max <span class="token operator">=</span> <span class="token class-name">LocalDateTime</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span><span class="token string">&quot;2022-10-17 23:40:58&quot;</span><span class="token punctuation">,</span> ateTimeFormatter<span class="token punctuation">.</span><span class="token function">ofPattern</span><span class="token punctuation">(</span><span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="时间字段总结" tabindex="-1"><a class="header-anchor" href="#时间字段总结" aria-hidden="true">#</a> 时间字段总结</h4><p><a href="https://www.cnblogs.com/zzlcome/p/11093292.html" target="_blank" rel="noopener noreferrer">java8新特性LocalDateTime字符串转时间比较大小<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span></a></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 接收参数时使用 - 数据库精确到秒 但是前端只到日 实体类类型使用 LocalDate</span>
<span class="token annotation punctuation">@DateTimeFormat</span><span class="token punctuation">(</span>pattern <span class="token operator">=</span> <span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">)</span>
<span class="token comment">// 返回结果时使用 - 数据库精确到秒 但是前端只到日 实体类类型使用 LocalDate</span>
<span class="token annotation punctuation">@JsonFormat</span><span class="token punctuation">(</span>pattern <span class="token operator">=</span> <span class="token string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span class="token punctuation">)</span>		
<span class="token keyword">private</span> <span class="token class-name">LocalDateTime</span> birthday<span class="token punctuation">;</span>

<span class="token comment">// 使用注解可在数据库可对应多种格式类型 然后前端赋值对应的格式时间 </span>
<span class="token class-name">Date</span> 		  <span class="token comment">// - 时间类型 可对应多种格式 时分秒 对应数据库的时间数据类型</span>
<span class="token class-name">LocalDateTime</span> <span class="token comment">// - 时间类型 只能是: 年月日 时分秒 对应数据库的时间数据类型</span>
<span class="token class-name">LocalDate</span>     <span class="token comment">// - 时间类型 可以是: 年月日 对应数据库的时间数据类型</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="bigdecimal-精确计算" tabindex="-1"><a class="header-anchor" href="#bigdecimal-精确计算" aria-hidden="true">#</a> BigDecimal | 精确计算</h3><blockquote><p>类型 - 精确计算 适用于关于金钱属性字段</p></blockquote><p><strong>赋值: 推荐使用双引号</strong></p><ul><li>new BigDecimal(&quot;1002&quot;);</li></ul><p><strong>计算方式:</strong></p><ul><li>加法 | add()</li><li>减法 | subtract()</li><li>乘法 | multiply()</li><li>除法 | divide()</li></ul><p><strong>转换:</strong></p><ul><li>BigDecimal --&gt; int | BigDecimal .intValue()</li></ul><h2 id="java-常用集合" tabindex="-1"><a class="header-anchor" href="#java-常用集合" aria-hidden="true">#</a> Java 常用集合</h2><h3 id="范性" tabindex="-1"><a class="header-anchor" href="#范性" aria-hidden="true">#</a> 范性</h3><p>限制录入的数据类型 - 数据类型只能是引用数据类型</p><p>范性集合-类型一致不需要强转</p><p>ArrayList&lt; 引用数据类型 &gt; fx = new ArrayList&lt; 引用数据类型 &gt;();</p><p>查看数据时有时候注意强制转换</p><p>范性集合在查询数据时可以不需要强转</p><p><strong>增强 for 循环</strong></p><ul><li>将被遍历的容器里的每一组数据赋值给新变量然后输出</li><li>for( 变量名 : 被遍历的容器 ) { } - 注意变量类型一致</li></ul><h3 id="arraylist-集合" tabindex="-1"><a class="header-anchor" href="#arraylist-集合" aria-hidden="true">#</a> ArrayList 集合</h3><blockquote><p>特性: 存储不唯一,有序插入,可以存储任意类型数据,下标从0开始</p></blockquote><p><strong>List 集合 API</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 创建ArrayList对象-集合容器 输出 - 可直接输出</span>
<span class="token class-name">ArrayList</span> 对象名  <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 增 - 类型可以不一样-内容可以一样 - 数据储存都转为object类(自动装箱)</span>
对象名 <span class="token punctuation">.</span> <span class="token function">add</span><span class="token punctuation">(</span>  值   <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 改 - 根据下标修改对应的数据</span>
对象名 <span class="token punctuation">.</span> set <span class="token punctuation">(</span> 下标 <span class="token punctuation">,</span> 修改内容  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 查 -根据下标查询对应的数据-查询后的类型都为-object-类</span>
<span class="token class-name">Object</span> 变量 <span class="token operator">=</span> 对象名 <span class="token punctuation">.</span> <span class="token function">get</span><span class="token punctuation">(</span> 下标  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 删 - 根据下标删除对应的数据</span>
对象名 <span class="token punctuation">.</span> <span class="token function">remove</span><span class="token punctuation">(</span>  下标  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 查看集合长度</span>
<span class="token keyword">int</span> 变量 <span class="token operator">=</span> 对象名 <span class="token punctuation">.</span> <span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 判断集合是否有某个元素 - 类型布尔</span>
对象名 <span class="token punctuation">.</span> contains <span class="token punctuation">(</span> 值  <span class="token punctuation">)</span><span class="token operator">:</span>
<span class="token comment">// 集合转为数组 - 数据储存都转为object类-数组类型也为object类</span>
<span class="token class-name">Object</span><span class="token punctuation">[</span><span class="token punctuation">]</span> 数组名 <span class="token operator">=</span> 对象名 <span class="token punctuation">.</span> <span class="token function">toArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 清除集合所有的元素</span>
对象名 <span class="token punctuation">.</span> <span class="token function">clear</span><span class="token punctuation">(</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>List 集合 API 实测</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">ArrayList</span></span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ArraylistClass</span> <span class="token punctuation">{</span>
    <span class="token doc-comment comment">/**
	 * 集合 - ArrayList对象-集合容器
	 * 存储不唯一,有序插入,可以存储任意类型数据,下标从0开始
	 */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">//创建ArrayList对象-集合容器</span>
        <span class="token class-name">ArrayList</span> arrayList  <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//增 - 类型可以不一样-内容可以一样 - 数据储存都转为object类(自动装箱)</span>
        arrayList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        arrayList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        arrayList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;增加&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        arrayList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token char">&#39;W&#39;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        arrayList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//输出 - 可直接输出</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>arrayList<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//改 - 根据下标修改对应的数据</span>
        arrayList<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//查 -根据下标查询对应的数据-查询后的类型都为-object-类</span>
        <span class="token class-name">Object</span> cha <span class="token operator">=</span> arrayList<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>cha<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//删 - 根据下标删除对应的数据</span>
        arrayList<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>arrayList<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//查看集合长度</span>
        <span class="token keyword">int</span> cd <span class="token operator">=</span> arrayList<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>cd<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">//其他方法</span>
        <span class="token comment">//判断集合是否有某个元素 - 类型布尔</span>
        <span class="token keyword">boolean</span> m <span class="token operator">=</span> arrayList<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token string">&quot;增加&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>m<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//集合转为数组 - 数据储存都转为object类-数组类型也为object类</span>
        <span class="token class-name">Object</span><span class="token punctuation">[</span><span class="token punctuation">]</span> sz <span class="token operator">=</span> arrayList<span class="token punctuation">.</span><span class="token function">toArray</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> sz<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>sz<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment">//清楚集合所有的元素</span>
        arrayList<span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>arrayList<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="hashset-集合" tabindex="-1"><a class="header-anchor" href="#hashset-集合" aria-hidden="true">#</a> hashset 集合</h3><p><strong>特性:</strong></p><ul><li>储存一组无序且数据内容唯一的集合-没有下标</li><li>没有-改-查-方法</li><li>Hashset集合遍历-没有下标只能使用增强for循环</li></ul><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 创建hashset集合</span>
<span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> 对象名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 根据元素值删除</span>
集合名 <span class="token punctuation">.</span> <span class="token function">remove</span><span class="token punctuation">(</span>  值  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// HashSet集合转ArrayList 使用ArrayList构造方法进行转换</span>
<span class="token class-name">ArrayList</span><span class="token operator">&lt;</span>类型<span class="token operator">&gt;</span> 对象名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token operator">&lt;</span>类型<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token class-name">HashSet</span>集合名<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// ArrayList集合转HashSet 使用HashSet构造方法进行转换 可以去重</span>
<span class="token class-name">HashSet</span><span class="token operator">&lt;</span>类型<span class="token operator">&gt;</span> 对象名 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token operator">&lt;</span>类型<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token class-name">ArrayList</span>集合名<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>hashset 集合 实测</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HashsetClass</span> <span class="token punctuation">{</span>
    <span class="token doc-comment comment">/**
	 * Hashset - 储存一组无序且数据内容唯一的集合-没有下标
	 */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">//创建hashset集合 - 导包</span>
        <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> hs <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//储存数据 - 无序且没有下标</span>
        hs<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        hs<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">84</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        hs<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">82</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        hs<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">48</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        hs<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//删 - 根据元素输出数据</span>
        hs<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token number">48</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//判断是否包含某个元素-类型布尔</span>
        <span class="token class-name">Boolean</span> a <span class="token operator">=</span> hs<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//清空所有元素数据</span>
        <span class="token comment">//hs.clear();</span>
        <span class="token comment">//获取集合长度</span>
        <span class="token keyword">int</span> cd <span class="token operator">=</span> hs<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>cd<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//集合输出</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>hs<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//Hashset集合遍历-没有下标只能使用增强for循环 </span>
        <span class="token comment">//注意类型要对应</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> m <span class="token operator">:</span> hs<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>m<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment">//HashSet集合转ArrayList</span>
        <span class="token comment">//使用ArrayList构造方法进行转换</span>
        <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> al <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>hs<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>al<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//ArrayList集合转HashSet - 可以去重</span>
        <span class="token comment">//使用HashSet构造方法进行转换</span>
        <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> hs2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashSet</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span>al<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="hashmap-集合" tabindex="-1"><a class="header-anchor" href="#hashmap-集合" aria-hidden="true">#</a> hashmap 集合</h3><p><strong>特性:</strong></p><ul><li><p>HashMap 集合是一种依照键〈key)值(value)对存储数据的容器，键(key)很像下标，在List中下标是整数。</p></li><li><p>map不是Collection接口下的</p></li><li><p>在Map中键(key)可以使任意类型的对象。Map中不能有重复的键(Key),每个键(key)都有一个对应的值(value)。一个键(key)和它对应的值构成map集合中的一个元素。</p></li></ul><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 创建HashMap&lt;键, 值&gt;集合 HashMap集合无序-键和值的数据类型可自定义</span>
<span class="token class-name">HashMap</span><span class="token operator">&lt;</span> 键<span class="token operator">-</span>key<span class="token punctuation">,</span>值<span class="token operator">-</span>value <span class="token operator">&gt;</span>  map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token operator">&lt;</span> 键<span class="token operator">-</span>key<span class="token punctuation">,</span>值<span class="token operator">-</span>value <span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 增-put - 键和值的类型要对应 输出类型object 利用键的名称相同可达到修改的作用  - 覆盖</span>
map<span class="token punctuation">.</span>put <span class="token punctuation">(</span> 键<span class="token punctuation">,</span>值 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 删 - 通过键来删除</span>
map<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span> 键 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 查</span>
map<span class="token punctuation">.</span>get <span class="token punctuation">(</span>键 key <span class="token punctuation">)</span>
<span class="token comment">// 判断是否包含键 - 值</span>
集合名<span class="token punctuation">.</span><span class="token function">containsKey</span><span class="token punctuation">(</span>键<span class="token punctuation">)</span>
集合名<span class="token punctuation">.</span><span class="token function">containsvalues</span><span class="token punctuation">(</span>值<span class="token punctuation">)</span>
<span class="token comment">// 获得所有的值 - 输出类型为set集合</span>
<span class="token class-name">Set</span><span class="token operator">&lt;</span> 键的类型 <span class="token operator">&gt;</span> 名字 <span class="token operator">=</span> 集合名 <span class="token punctuation">.</span> <span class="token function">values</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 获得所有的键 - 输出类型为set集合</span>
<span class="token class-name">Set</span><span class="token operator">&lt;</span> 键的类型 <span class="token operator">&gt;</span> 名字 <span class="token operator">=</span> 集合名 <span class="token punctuation">.</span> <span class="token function">keySet</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 遍历 增强for循环 获取键的对应值 输出键和值的拼接</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>hashmap 集合 实测</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">package</span> <span class="token namespace">study</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">HashMap</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">Set</span></span><span class="token punctuation">;</span>
<span class="token doc-comment comment">/**
 * HashMap 集合是一种依照键〈key)值(value)对存储数据的容器，键(key)很像下标，在List中下标是整数。
 * 在Map中键(key)可以使任意类型的对象。Map中不能有重复的键(Key),每个键(key)都有一个对应的值(value)。一个键(key)和它对应的值构成map集合中的一个元素。
 * Map集合存储的数据是键值对结构
 * Map集合存储的数据是无序的
 */</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Mappclass</span> <span class="token punctuation">{</span>
	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">//创建HashMap&lt;键, 值&gt;集合-指定键和值</span>
		<span class="token comment">//键相当于下标-唯一不能重复-类型可自定义</span>
		<span class="token comment">//值-类型可自定义</span>
		<span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//增-put - 键和值的类型要对应</span>
		map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;姓名&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;小渊&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;年龄&quot;</span><span class="token punctuation">,</span><span class="token number">24</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;性别&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;男&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;身高&quot;</span><span class="token punctuation">,</span><span class="token number">165.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//删 - 通过键来删除</span>
		map<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">&quot;性别&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//改 - 键唯一且不能重复-反之修改</span>
		map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;年龄&quot;</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//查 - 通过键来查询对应的值</span>
		<span class="token class-name">Object</span> a <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;姓名&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//查看hashmap的长度</span>
		<span class="token keyword">int</span> b <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;hashmap的长度: &quot;</span> <span class="token operator">+</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//输出HashMap集合的数据 - 可直接输出</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>map<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//判断HashMap是否包含指定键</span>
		<span class="token keyword">boolean</span> c <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">containsKey</span><span class="token punctuation">(</span><span class="token string">&quot;身高&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//判断HashMap是否包含指定值</span>
		<span class="token keyword">boolean</span> d <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">containsValue</span><span class="token punctuation">(</span><span class="token string">&quot;男&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;---------&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//遍历</span>
		<span class="token comment">//获得所有的键 - 输出类型为set集合</span>
		<span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> set <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">keySet</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//增强for循环</span>
		<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">String</span> key <span class="token operator">:</span> set<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token comment">//获取键的对应值</span>
			<span class="token class-name">Object</span> value <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">//输出键和值的拼接</span>
			<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>key <span class="token operator">+</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>set<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//输出所有集合值</span>
		<span class="token class-name">Object</span> sa <span class="token operator">=</span> map<span class="token punctuation">.</span><span class="token function">values</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>sa<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="collections-api" tabindex="-1"><a class="header-anchor" href="#collections-api" aria-hidden="true">#</a> Collections API</h3><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 排序 - 升序 - 数值类型 - list集合</span>
<span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span> 集合名 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 反转 - 先升序后反转为倒序</span>
<span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span> 集合名 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 最大值</span>
<span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span> 集合名 <span class="token punctuation">)</span><span class="token punctuation">;</span>
影片案例<span class="token punctuation">.</span>png
<span class="token comment">// 最小值</span>
<span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span> 集合名 <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">//创建Arraylist集合</span>
    <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">19</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">42</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//排序 - 升序 - 数值类型 - list集合</span>
    <span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//反转 - 先升序后反转为倒序</span>
    <span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//最大值</span>
    <span class="token keyword">int</span> max <span class="token operator">=</span> <span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;最大值为: &quot;</span> <span class="token operator">+</span> max<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//最小值</span>
    <span class="token keyword">int</span> min <span class="token operator">=</span> <span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;最小值为: &quot;</span> <span class="token operator">+</span> min<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="比较器" tabindex="-1"><a class="header-anchor" href="#比较器" aria-hidden="true">#</a> 比较器</h3><p><strong>特性:</strong></p><ul><li>Comparator比较器 - 端口 | 可以把集合的对象元素按照对象里的某个属性排序</li><li>比较器排序规则: 大于-正数 小于-负数 大于-零 则从小到大-正序 | 反之则是倒序</li></ul><p><strong>步骤:</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 创建Comparator比较器 - 端口 | 匿名内部类</span>
<span class="token keyword">new</span> <span class="token class-name">Comparator</span><span class="token operator">&lt;</span>集合类型<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>    <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token class-name">Comparator</span><span class="token operator">&lt;</span>集合类型<span class="token operator">&gt;</span> 名字 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Comparator</span><span class="token operator">&lt;</span>集合类型<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>  重写比较器的方法  <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token comment">// 比较器的重写方法</span>
<span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">compare</span><span class="token punctuation">(</span><span class="token class-name">Personage</span> o1<span class="token punctuation">,</span> <span class="token class-name">Personage</span> o2<span class="token punctuation">)</span> <span class="token punctuation">{</span>   <span class="token keyword">if</span>语句相比o1和o2集合里对象的属性    <span class="token punctuation">}</span>
<span class="token comment">// 简化</span>
<span class="token keyword">return</span>  o1<span class="token punctuation">.</span>对象属性  <span class="token operator">-</span>  o2<span class="token punctuation">.</span>对象属性<span class="token punctuation">;</span>
<span class="token comment">// 进行排序</span>
<span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span> 集合名 <span class="token punctuation">,</span> 比较器名字 <span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">package</span> <span class="token namespace">com<span class="token punctuation">.</span>apai<span class="token punctuation">.</span>springbootvue</span><span class="token punctuation">;</span>

<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">Collections</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">Comparator</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">LinkedList</span></span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">List</span></span><span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Mmm</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">LinkedList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">38</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Comparator</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> comparator <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Comparator</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token annotation punctuation">@Override</span>
            <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">compare</span><span class="token punctuation">(</span><span class="token class-name">Integer</span> o1<span class="token punctuation">,</span> <span class="token class-name">Integer</span> o2<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> o1 <span class="token operator">-</span> o2<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
        <span class="token class-name">Collections</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span>list<span class="token punctuation">,</span>comparator<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">Integer</span> integer <span class="token operator">:</span> list<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>integer<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>案例:</strong></p><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220724092417222.png" alt="image-20220724092417222"></p><h2 id="异常-自定义-jdbc" tabindex="-1"><a class="header-anchor" href="#异常-自定义-jdbc" aria-hidden="true">#</a> 异常-自定义 | JDBC</h2><h3 id="异常" tabindex="-1"><a class="header-anchor" href="#异常" aria-hidden="true">#</a> 异常</h3><p><strong>组成: Throwable - 顶级异常</strong></p><ul><li><p>Exception - 能解决的异常</p><p>RunTimeException - 运行时异常</p></li></ul><p>​ 非运行时异常 - 检查异常</p><ul><li>Error - 无法解决的异常 -内存不足</li></ul><h4 id="常见的异常" tabindex="-1"><a class="header-anchor" href="#常见的异常" aria-hidden="true">#</a> 常见的异常</h4><ol><li>算术异常 ArithmeticException</li><li>下标越界异常 IndexOutOfBoundsException</li><li>空指针异常 NullPointerException</li><li>数字转换异常 NumberFormatException</li></ol><h4 id="异常处理" tabindex="-1"><a class="header-anchor" href="#异常处理" aria-hidden="true">#</a> 异常处理</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 异常处理</span>
<span class="token keyword">try</span> <span class="token punctuation">{</span>
	<span class="token comment">//可能出现异常的代码</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token comment">//try里出现异常则执行此处</span>
<span class="token punctuation">}</span><span class="token keyword">finally</span> <span class="token punctuation">{</span>
	<span class="token comment">//无论try是否出现异常的将执行</span>
	<span class="token comment">//打印详细的异常信息: e.printStackTrace();</span>
	<span class="token comment">//获取异常信息: System.out.println(e.getMessage());</span>
<span class="token punctuation">}</span>

<span class="token comment">// 多重异常处理 根据try出现的不同异常选择进入不同的catch执行</span>
<span class="token keyword">try</span> <span class="token punctuation">{</span>
	<span class="token comment">//根据try出现的不同异常选择进入不同的catch执行</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">ArithmeticException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token comment">//当try为 算术异常 是执行</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">IndexOutOfBoundsException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token comment">//当try为 下标越界异常 是执行</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">NullPointerException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token comment">//当try为 空指针异常 是执行</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">NumberFormatException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token comment">//当try为 数字转换异常 是执行</span>
<span class="token punctuation">}</span>


</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="异常信息处理" tabindex="-1"><a class="header-anchor" href="#异常信息处理" aria-hidden="true">#</a> 异常信息处理</h4><ul><li><p>getMessage(): String | 输出异常的描述信息</p></li><li><p>getLocalizedMessage() | 输出本地化的描述信息，一般此方法可被子类所覆盖，缺省实现与getMessage()输出信息一致</p></li><li><p>printStackTrace() | 将异常栈打印到输出流中，此为一类方法，默认打印到console控制台，也可以显式指定输出流</p></li><li><p>fillInStackTrace()</p></li></ul><h4 id="声明异常" tabindex="-1"><a class="header-anchor" href="#声明异常" aria-hidden="true">#</a> 声明异常</h4><p><strong>throws 跟 throw的区别</strong></p><ul><li>throws写在方法的定义上,把异常抛给方法的调用者</li><li>throw 写在方法体上,抛出一个具体的异常对象</li></ul><p>throws Exception: 在方法调用出可选择再次抛出异常或者使用try解决异常</p><blockquote><p>当方法里出现异常时可在方法名后使用 - throws Exception 抛出异常给方法调用处解决</p></blockquote><p>throw</p><blockquote><p>写在方法体中,抛出一个具体的异常对象</p></blockquote><p>throw new Exception();</p><blockquote><p>制造异常使之进入catch执行回滚</p></blockquote><h4 id="系统日志的级别" tabindex="-1"><a class="header-anchor" href="#系统日志的级别" aria-hidden="true">#</a> 系统日志的级别:</h4><p>DEBUG &lt; INFO &lt; WARN &lt; ERROR &lt; FATAL</p><h3 id="自定义异常" tabindex="-1"><a class="header-anchor" href="#自定义异常" aria-hidden="true">#</a> 自定义异常</h3><blockquote><p>持久层的异常自动在业务层捕获，业务层需要将此异常抛给表示层</p><p>使用自定义异常来描述与业务相关的异常消息，然后通知用户</p></blockquote><p>往上抛出异常 | throw .....</p><h4 id="异常层-自定义异常类" tabindex="-1"><a class="header-anchor" href="#异常层-自定义异常类" aria-hidden="true">#</a> 异常层 - 自定义异常类</h4><blockquote><p>所有业务异常的的超类 继承 RuntimeException</p><p>继承 业务异常的的超类 重写方法 例如:</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token doc-comment comment">/**
 * 所有业务异常的的超类
 */</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ServiceException</span> <span class="token keyword">extends</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">ServiceException</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">ServiceException</span><span class="token punctuation">(</span><span class="token class-name">String</span> message<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span>message<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token class-name">ServiceException</span><span class="token punctuation">(</span><span class="token class-name">String</span> message<span class="token punctuation">,</span> <span class="token class-name">Throwable</span> cause<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span>message<span class="token punctuation">,</span> cause<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="自定义抛出异常" tabindex="-1"><a class="header-anchor" href="#自定义抛出异常" aria-hidden="true">#</a> 自定义抛出异常</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">throw</span> <span class="token keyword">new</span> 自定义异常类名<span class="token punctuation">(</span><span class="token string">&quot;内容_可根据重载赋值&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h4 id="异常出现时接收异常" tabindex="-1"><a class="header-anchor" href="#异常出现时接收异常" aria-hidden="true">#</a> 异常出现时接收异常</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">try</span> <span class="token punctuation">{</span>
    tpaylogService<span class="token punctuation">.</span><span class="token function">addplaceanorder</span><span class="token punctuation">(</span>tpaylogVo<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 出现异常 判断是否是 自定义的异常 | [ e instanceof 自定义的异常类 ]</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>e <span class="token keyword">instanceof</span> <span class="token class-name">IntegralException</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ResponseResult</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">999</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ResponseResult</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token string">&quot;网络异常 稍后再试&quot;</span><span class="token punctuation">,</span> <span class="token number">999</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>
    <span class="token comment">// 判断是否是业务异常</span>
    e <span class="token keyword">instanceof</span> <span class="token class-name">ServiceException</span>
    <span class="token comment">// 自定义异常的内容		</span>
    e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token comment">// 系统发生的异常	</span>
    e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="jdbc-数据库" tabindex="-1"><a class="header-anchor" href="#jdbc-数据库" aria-hidden="true">#</a> JDBC 数据库</h3><h4 id="数据库连接步骤" tabindex="-1"><a class="header-anchor" href="#数据库连接步骤" aria-hidden="true">#</a> 数据库连接步骤</h4><p><strong>1.获取数据库信息</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 语法:  String url = &quot;jdbc:mysql:// ip地址 : 端口 / 数据库名称 ?useUnicode=true&amp;characterEncoding=UTF-8&amp; 时区 &quot;;</span>
<span class="token class-name">String</span> url <span class="token operator">=</span> <span class="token string">&quot;jdbc:mysql://127.0.0.1:3306/date_0316_jdbc?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai&quot;</span><span class="token punctuation">;</span>
<span class="token comment">// 数据库账号</span>
<span class="token class-name">String</span> user <span class="token operator">=</span> <span class="token string">&quot;root&quot;</span><span class="token punctuation">;</span>
<span class="token comment">// 数据库密码</span>
<span class="token class-name">String</span> password <span class="token operator">=</span> <span class="token string">&quot;123456&quot;</span><span class="token punctuation">;</span>
<span class="token comment">// 数据库驱动路径 驱动的安装: 创建文件夹 - lib 将驱动文件复制到文件夹</span>
<span class="token class-name">String</span> driverclass <span class="token operator">=</span> <span class="token string">&quot;com.mysql.cj.jdbc.Driver&quot;</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>2.注册驱动(可省略但不建议)</strong></p><blockquote><p>会有异常 - (数据库驱动路径变量名)</p><p>Class.forName(driverclass);</p></blockquote><p><strong>3.连接数据库获取对象</strong></p><blockquote><p>导包两个-会有异常 ( url , 账号 , 密码 )</p><p>Connection conn = DriverManager.getConnection(url, user, password);</p></blockquote><p><strong>4.写sql语句</strong></p><blockquote><p>String sql = &quot; 数据库的表增删改查 SQL 语句 &quot;;</p></blockquote><p><strong>5.sql预编译</strong></p><blockquote><p>导包-预编译sql语句变量名</p><p>PreparedStatement 编译名 = 连接数据库变量名.prepareStatement( sql语句变量名 );</p><p>PreparedStatement pst = conn.prepareStatement(sql);</p></blockquote><p><strong>6.执行sql语句</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 增删改 执行编译后的变量名,并输出是否成功受影响的行数</span>
<span class="token keyword">int</span> 执行名 <span class="token operator">=</span> 编译名 <span class="token punctuation">.</span> <span class="token function">executeUpdate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> result <span class="token operator">=</span> pst<span class="token punctuation">.</span><span class="token function">executeUpdate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;受影响的行数为: &quot;</span> <span class="token operator">+</span> result <span class="token operator">+</span> <span class="token string">&quot; 行&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 查 执行时时使用 - executeQuery() </span>
<span class="token class-name">ResultSet</span> 执行名 <span class="token operator">=</span> 编译名 <span class="token punctuation">.</span> <span class="token function">executeQuery</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">ResultSet</span> rs <span class="token operator">=</span> pst<span class="token punctuation">.</span><span class="token function">executeQuery</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
使用<span class="token keyword">while</span>循环遍历 <span class="token operator">-</span> <span class="token keyword">while</span><span class="token punctuation">(</span>执行名<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> 执行一次向下一排<span class="token punctuation">,</span>当一排数据为空则停止
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>7.关闭连接</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 增删改时</span>
<span class="token comment">// 3.连接数据库获取对象 - 关闭</span>
conn<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 5.sql预编译 - 关闭</span>
pst<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 查询表数据时</span>
<span class="token comment">// 6.执行sql语句 - 关闭</span>
rs<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="jdbc-事务" tabindex="-1"><a class="header-anchor" href="#jdbc-事务" aria-hidden="true">#</a> jdbc - 事务</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 默认是自动提交</span>
conn<span class="token punctuation">.</span><span class="token function">setAutoCommit</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token operator">--</span> 关闭自动提交<span class="token punctuation">,</span>相当于开启事物
conn<span class="token punctuation">.</span><span class="token function">setAutoCommit</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token operator">--</span> 开启自动提交<span class="token punctuation">,</span>相当于关闭事物
<span class="token comment">// 执行过程</span>
<span class="token comment">// 执行sql语句 语句为一体,全部执行成功则成功 当使用sql语句执行成功则确认-提交</span>
conn<span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 当使用sql语句执行失败则撤销-回滚</span>
conn<span class="token punctuation">.</span><span class="token function">rollback</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 制造异常使之进入catch执行回滚</span>
<span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Exception</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="事务的四大特性" tabindex="-1"><a class="header-anchor" href="#事务的四大特性" aria-hidden="true">#</a> 事务的四大特性:</h4><p>1、原子性（Atomicity）：化学中的原子指不可再分的基本微粒，数据库中原子性强调事务是一个不可分割的整体，事务开始后所有操作要么全部成功，要么全部失败，不可能停滞在中间某个环节。如果事务执行过程中出错就会回滚到事务开始前的状态，所有的操作就像没有发生一样不会对数据库有任何影响。</p><p>2、一致性（Consistency）：事务必须使数据库从一个一致性状态变换到另一个一致性状态，即一个事务执行之前和执行之后都必须处于一致性状态。拿转账来说，假设用户A和用户B两者的钱加起来一共是5000，那么不管A和B之间如何转账，转几次账，事务结束后两个用户的钱相加起来应该还是5000，这就是事务的一致性。</p><p>3、隔离性（Isolation）：当多个用户并发访问数据库时，比如操作同一张表时，数据库为每一个用户开启的事务，不能被其他事务的操作所干扰，多个并发事务之间要相互隔离，比如A正在从一张银行卡中取钱，在A取钱的过程结束前，B不能向这张卡转入钱。</p><p>4、持久性（Durability）：一个事务一旦被提交，则对数据库的所有更新将被保存到数据库中，不能回滚。</p><h2 id="file-流" tabindex="-1"><a class="header-anchor" href="#file-流" aria-hidden="true">#</a> File|流 |</h2><h3 id="file-文件-目录" tabindex="-1"><a class="header-anchor" href="#file-文件-目录" aria-hidden="true">#</a> File 文件 | 目录</h3><h4 id="创建目录" tabindex="-1"><a class="header-anchor" href="#创建目录" aria-hidden="true">#</a> 创建目录</h4><blockquote><p>\ | / | +File.separator+ | 逗号 , 分隔</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 创建目录一</span>
    <span class="token class-name">File</span> file1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;D:\\qq.bin&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>file1<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 创建目录二</span>
    <span class="token class-name">File</span> file2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;D:/qq.bin&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">File</span> file3 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;D:&quot;</span><span class="token operator">+</span><span class="token class-name">File</span><span class="token punctuation">.</span>separator<span class="token operator">+</span><span class="token string">&quot;qq.bin&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>file2<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>file3<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 创建目录三</span>
    <span class="token class-name">File</span> file4 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;D:&quot;</span> <span class="token punctuation">,</span> <span class="token string">&quot;qq&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">File</span> file5 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;D:/qq&quot;</span> <span class="token punctuation">,</span> <span class="token string">&quot;bin&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">File</span> file6 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span>file4 <span class="token punctuation">,</span> <span class="token string">&quot;bin&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="常用方法-api" tabindex="-1"><a class="header-anchor" href="#常用方法-api" aria-hidden="true">#</a> 常用方法 API</h4><blockquote><p>File file1 = new File(&quot;D:\qq.bin&quot;); 调用</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 创建目录 多层目录时用mkdirs() 一层可以用mkdir()</span>
<span class="token keyword">boolean</span>  <span class="token operator">-</span>  变量名<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 创建文件</span>
<span class="token keyword">boolean</span>  <span class="token operator">-</span>  变量名<span class="token punctuation">.</span><span class="token function">createNewFile</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 删除文件</span>
<span class="token keyword">boolean</span>  <span class="token operator">-</span>  变量名<span class="token punctuation">.</span><span class="token function">delete</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 输出路径</span>
<span class="token class-name">String</span> <span class="token operator">-</span> 变量名<span class="token punctuation">.</span><span class="token function">getAbsolutePath</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 获取文件或目录名称</span>
<span class="token class-name">String</span> <span class="token operator">-</span> 变量名<span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 获取父类目录的名称</span>
<span class="token class-name">String</span> <span class="token operator">-</span> 变量名<span class="token punctuation">.</span><span class="token function">getParent</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 获取父类目录的file实例</span>
<span class="token class-name">File</span> <span class="token operator">-</span> 变量名<span class="token punctuation">.</span><span class="token function">getParentFile</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 判断文件是否存在</span>
<span class="token keyword">boolean</span>  <span class="token operator">-</span>  变量名<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 判断是否为文件</span>
<span class="token keyword">boolean</span>  <span class="token operator">-</span>  变量名<span class="token punctuation">.</span><span class="token function">isFile</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 判断是否为目录</span>
<span class="token keyword">boolean</span>  <span class="token operator">-</span>  变量名<span class="token punctuation">.</span><span class="token function">isDirectory</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 获取上次修</span>
<span class="token keyword">long</span> <span class="token operator">-</span> 变量名<span class="token punctuation">.</span><span class="token function">lastModified</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 距时间原点的毫秒值</span>
<span class="token comment">// 返回文件大小</span>
<span class="token keyword">long</span> <span class="token operator">-</span> 变量名<span class="token punctuation">.</span><span class="token function">length</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 获取路径下的目录和文件</span>
<span class="token class-name">File</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">-</span>  变量名<span class="token punctuation">.</span><span class="token function">listFiles</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>文件创建 递归 - 遍历文件目录所有文件夹和文件</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 文件创建 递归 - 遍历文件目录所有文件夹和文件</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">File_digui</span> <span class="token punctuation">{</span>

	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// - 自动导包  ctrl + shift + o</span>
		<span class="token comment">//创建目录</span>
		<span class="token class-name">File</span> file <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;C:/Users/Lujun/Documents/你是我的月亮/与太阳有关&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">// 方法 传入-目录 和 目录层级</span>
		<span class="token function">show</span><span class="token punctuation">(</span>file<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token punctuation">}</span>
	<span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">show</span><span class="token punctuation">(</span><span class="token class-name">File</span> file<span class="token punctuation">,</span> <span class="token keyword">int</span> spaces<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token comment">// 当目录不存在为空时方法停止</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span>file <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token comment">// 判断是否为目录</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span>file<span class="token punctuation">.</span><span class="token function">isDirectory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token comment">// 获取目录中所有文件 - 使用数组储存</span>
			<span class="token class-name">File</span><span class="token punctuation">[</span><span class="token punctuation">]</span> listFiles <span class="token operator">=</span> file<span class="token punctuation">.</span><span class="token function">listFiles</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token comment">// 增强for循环遍历数组 - 快速创建增强for循环: fore + 代码提示</span>
			<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">File</span> file2 <span class="token operator">:</span> listFiles<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token comment">// System.out.println(&quot;文件大小: &quot; + file2.length() + &quot; 字节&quot;);</span>
				<span class="token comment">// 按目录层级 不换行添加空格 每一层目录多增加一个空格 - \t:空格</span>
				<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> spaces<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;\t&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token punctuation">}</span>
				<span class="token comment">// 输出目录名称</span>
				<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>file2<span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token comment">// 再次使用方法 传入 为每层的目录</span>
				<span class="token function">show</span><span class="token punctuation">(</span>file2<span class="token punctuation">,</span> spaces <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-流" tabindex="-1"><a class="header-anchor" href="#io-流" aria-hidden="true">#</a> Io 流</h3><p>文件中的换行是由两个独立字节组成: \r回车(13) \n换行(10)</p><h4 id="字节流" tabindex="-1"><a class="header-anchor" href="#字节流" aria-hidden="true">#</a> 字节流</h4><blockquote><p>JDK7 | try(创建流对象){ }</p><p>IO流创建后,会被try自动管理,在程序执行完后,自动关流释放资源,不需要人为的关闭流</p></blockquote><h5 id="输入字节流" tabindex="-1"><a class="header-anchor" href="#输入字节流" aria-hidden="true">#</a> 输入字节流</h5><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token class-name">FileInputStream</span> fis <span class="token operator">=</span>  <span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span><span class="token string">&quot;文件路径&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 查询文件的内容</span>
变量名<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// 依次输出字符的ACS||表对应的数据 - 当输出到最后没有字符时为 -1</span>
<span class="token comment">// 输出时使用char强转输出对应的字符</span>
<span class="token comment">// 根据判断是否为-1 进行循环</span>
<span class="token comment">// 关闭流</span>
变量名<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="输出字节流" tabindex="-1"><a class="header-anchor" href="#输出字节流" aria-hidden="true">#</a> 输出字节流</h5><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 默认追加为覆盖 - 如果追加不覆盖则在目录文件后加上 true</span>
<span class="token comment">// 输出时文件不存在则自动创建 - 目录不会自动创建</span>
<span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">&quot;文件路径&quot;</span><span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 追加字符 | ACS||表对应的数据</span>
变量名<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token number">97</span><span class="token punctuation">)</span>
变量名<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>
<span class="token comment">// 追加字符串</span>
变量名<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;字符串&quot;</span><span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token comment">// 字符串转数组</span>
<span class="token string">&quot;字符串&quot;</span><span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
变量名<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;字符串&quot;</span><span class="token punctuation">.</span><span class="token function">tostring</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
变量名<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;字符串&quot;</span><span class="token punctuation">.</span><span class="token function">tostring</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token string">&quot;GBK&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
变量名<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> b<span class="token punctuation">,</span> <span class="token keyword">int</span> off<span class="token punctuation">,</span> <span class="token keyword">int</span> len<span class="token punctuation">)</span>
<span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> b<span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span>
abcdef   <span class="token operator">-&gt;</span>   bcd
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="缓冲流" tabindex="-1"><a class="header-anchor" href="#缓冲流" aria-hidden="true">#</a> 缓冲流</h4><blockquote><p>缓存是IO的一种性能优化，缓存流为IO流增加了内存缓存区，</p></blockquote><h5 id="字节缓冲流" tabindex="-1"><a class="header-anchor" href="#字节缓冲流" aria-hidden="true">#</a> 字节缓冲流</h5><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 输出</span>
<span class="token class-name">BufferedOutputStream</span> bos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BufferedOutputStream</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">&quot;路径&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 输入</span>
<span class="token class-name">BufferedInputStream</span> bis <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BufferedInputStream</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span><span class="token string">&quot;路径&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="字符缓冲流" tabindex="-1"><a class="header-anchor" href="#字符缓冲流" aria-hidden="true">#</a> 字符缓冲流</h5><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 输出</span>
<span class="token class-name">BufferedWriter</span> bw <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BufferedWriter</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileWriter</span><span class="token punctuation">(</span><span class="token string">&quot;路径&quot;</span><span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
变量名 <span class="token punctuation">.</span> <span class="token function">newLine</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">// 换行</span>
<span class="token comment">// 输入</span>
<span class="token class-name">BufferedReader</span> br <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BufferedReader</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileReader</span><span class="token punctuation">(</span><span class="token string">&quot;路径&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
变量名 <span class="token punctuation">.</span> <span class="token function">readLine</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// 每次读取一行  末尾为null</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="转换流" tabindex="-1"><a class="header-anchor" href="#转换流" aria-hidden="true">#</a> 转换流</h4><blockquote><p>转换流: 如果文件中英文混合 转换流可以完美的输入与输出,不会造成乱码</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 字节输入流转换字符输入流 - 输入</span>
<span class="token keyword">new</span> <span class="token class-name">InputStreamReader</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span><span class="token string">&quot;路径&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">&quot;gbk:指定的编码格式&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 字符输出流转换字节输出流 - 输出</span>
<span class="token keyword">new</span> <span class="token class-name">OutputStreamWriter</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">&quot;路径&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">&quot;gbk:指定的编码格式&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="打印流" tabindex="-1"><a class="header-anchor" href="#打印流" aria-hidden="true">#</a> 打印流</h4><blockquote><p>只有输出流，没有输入流 | System.out，System.err是PrintStream的实例变量</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 字节打印输出流</span>
<span class="token keyword">new</span> <span class="token class-name">PrintStream</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">&quot;地址&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 字符打印输出流 - true:自动刷新</span>
<span class="token keyword">new</span> <span class="token class-name">PrintWriter</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileWriter</span><span class="token punctuation">(</span><span class="token string">&quot;地址&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token comment">// 不会换行 且会转换成对应的字符输出</span>
pout<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token number">97</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token comment">// 特有输出方法</span>
pout<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token number">97</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 会直接输出不会转换 不会换行</span>
pout<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;打印流 直接输出到文件&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 会换行</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="数据流" tabindex="-1"><a class="header-anchor" href="#数据流" aria-hidden="true">#</a> 数据流</h4><p>数据流只有字节流，没有字符流</p><p>数据流都是处理流，不是节点流</p><p>数据流只能操作基本数据类型和字符串，对象流还可以操作对象</p><p>数据流写入的是二进制数据，无法通过记事本查看</p><p>通过数据流写入的数据需要通过对应的数据输入流读取</p><h4 id="对象流" tabindex="-1"><a class="header-anchor" href="#对象流" aria-hidden="true">#</a> 对象流</h4><h5 id="序列化" tabindex="-1"><a class="header-anchor" href="#序列化" aria-hidden="true">#</a> 序列化</h5><blockquote><p>对象流输出对象 - 序列对象-存档</p></blockquote><p>new ObjectOutputStream(new FileOutputStream(&quot;地址&quot;));</p><p>序列化名.writeObject(对象名);</p><h5 id="序列化对象" tabindex="-1"><a class="header-anchor" href="#序列化对象" aria-hidden="true">#</a> 序列化对象</h5><blockquote><p>注意：在使用对象流操作对象时会报错 java.io.NotSerializableException，因为对象进行序列化和反序列化时实体类需要实现Serializable接口</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 序列化-id | @SuppressWarnings(&quot;serial&quot;) // 压制序列化版本ID好的声明警告</span>
<span class="token comment">// 指定序列号版本ID</span>
<span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token keyword">long</span> serialversionUID <span class="token operator">=</span> <span class="token number">1L</span><span class="token punctuation">;</span>
<span class="token comment">// 序列化后会生成一个序列id号,修改对象后在反序列化时会不兼容报错 - 指定id号后则不会</span>
<span class="token comment">// 成员常量不被序列化</span>
<span class="token keyword">transient</span> 修饰
<span class="token keyword">private</span>  <span class="token keyword">transient</span> <span class="token keyword">int</span> 变量名<span class="token punctuation">;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="反序列化" tabindex="-1"><a class="header-anchor" href="#反序列化" aria-hidden="true">#</a> 反序列化</h5><blockquote><p>对象流输出对象 - 反序列对象-读档 获取的对象为object需要强转成对象类型</p></blockquote><p>new ObjectInputStream(new FileInputStream(&quot;地址&quot;);</p><p>(对象类型) 反序列化名 .readObject();</p><h4 id="properties-文件" tabindex="-1"><a class="header-anchor" href="#properties-文件" aria-hidden="true">#</a> properties 文件</h4><blockquote><p>properties文件是数据为键值对格式的文件,这种文件跟文件的后缀没有关系,</p><p>只跟数据的存储形式有关</p><p>主要用于项目的信息配置</p></blockquote><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 创建属性对象</span>
<span class="token class-name">Properties</span> props <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Properties</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 将Properties的键和值写入文件 - 备注会转码</span>
props<span class="token punctuation">.</span><span class="token function">store</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">&quot;地址&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">&quot;备注&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 将文件的数据输入到Properties</span>
props<span class="token punctuation">.</span><span class="token function">load</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span><span class="token string">&quot;地址&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 使用键输出对应的值</span>
props<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token string">&quot;键&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 获取键</span>
<span class="token comment">// 	Set&lt;String&gt; keys1 = props.stringPropertyNames();</span>

<span class="token comment">// 作为map集合</span>
<span class="token comment">// 添加文件 - 键和值对应</span>
props<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;键&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;值&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 获取键</span>
<span class="token class-name">Set</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> keys <span class="token operator">=</span> props<span class="token punctuation">.</span><span class="token function">keySet</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// </span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="线程-网络编程" tabindex="-1"><a class="header-anchor" href="#线程-网络编程" aria-hidden="true">#</a> 线程 | 网络编程</h2><h3 id="多线程" tabindex="-1"><a class="header-anchor" href="#多线程" aria-hidden="true">#</a> 多线程</h3><p>进程: 程序分配资源最小单位为线程提供的容器,任何一个进程内部至少有一个线程--main主线程</p><p>多线程的作用: 充分利用CPU资源，提高程序的并行性，提高处理任务效率避免程序阻塞(blocked)-- 异步编程(不用等待)</p><p><strong>.run()与start()方法区别</strong></p><ul><li>run() - 代表线程要执行的任务,当使用线程对象调用时，不会开启新的线程，只是普通方法的调用</li><li>start() - 会开启新的线程，由CPU的调度，来执行run()方法</li></ul><h4 id="线程" tabindex="-1"><a class="header-anchor" href="#线程" aria-hidden="true">#</a> 线程</h4><blockquote><p>CPU调度的最小单元,多个线程共享进程内存资源线程必须依赖进程存在,线程是进程内部的一个程序的执行路径</p><p>参考: https://blog.csdn.net/AS011x/article/details/126931651</p></blockquote><p><strong>获取线程名称</strong></p><blockquote><p>Thread.currentThread().getName()</p><p>线程方法一: 可省略成 getname() 或者 this.getname()</p><p>通过 线程名.getName() 修改线程名</p></blockquote><p><strong>线程方法一: 继承Therad类</strong></p><blockquote><p>通过构造方法传参修改线程名</p></blockquote><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220724125649982.png" alt="image-20220724125649982"></p><p><strong>线程方法二: 实现 Runnable端口</strong></p><blockquote><p>直接传参修改线程名 new Thread(对象名, &quot;线程名&quot;);</p></blockquote><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220724125843307.png" alt="image-20220724125843307"></p><p><strong>匿名内部方法一: 匿名继承-Thread类的内部类</strong></p><blockquote><p>直接传参修改线程名 new Thread(&quot;线程名&quot;) { @Override };</p></blockquote><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220724125932361.png" alt="image-20220724125932361"></p><p><strong>匿名内部方法二: 匿名继承-Thread类 实现-Runnable接口 的内部类</strong></p><p><img src="https://apaiimages.oss-cn-guangzhou.aliyuncs.com/MD/image-20220724125959763.png" alt="image-20220724125959763"></p><h4 id="线程的生命周期" tabindex="-1"><a class="header-anchor" href="#线程的生命周期" aria-hidden="true">#</a> 线程的生命周期</h4><ol><li>新生(创建线程对象) new Thread()</li><li>就绪(调用线程对象的start方法,线程不会立马执行,线程需要去抢占cpu资源)</li><li>运行(抢占到cpu资源)</li><li>阻塞(线程运行的过程中释放cpu资源)</li><li>死亡(线程的任务执行完毕后,进入死亡状态)</li></ol><h4 id="线程优先级" tabindex="-1"><a class="header-anchor" href="#线程优先级" aria-hidden="true">#</a> 线程优先级</h4><p>优先级代表线程抢占到cpu资源的概率，不代表线程一定会优先执行</p><p>查看优先级: Thread名 . getPriority();</p><p><strong>修改优先级 (1-10)</strong></p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token class-name">Thread</span>名 <span class="token punctuation">.</span> <span class="token function">setPriority</span><span class="token punctuation">(</span> 优先级 <span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 最小优先级</span>
<span class="token class-name">Thread</span><span class="token punctuation">.</span><span class="token constant">MIN_PRIORITY</span>
<span class="token comment">// 最大优先级</span>
<span class="token class-name">Thread</span><span class="token punctuation">.</span><span class="token constant">MAX_PRIORITY</span>
<span class="token comment">// 默认优先级</span>
<span class="token class-name">Thread</span><span class="token punctuation">.</span><span class="token constant">NORM_PRIORITY</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="常用方法" tabindex="-1"><a class="header-anchor" href="#常用方法" aria-hidden="true">#</a> 常用方法</h4><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">--</span>获取线程的名称
    <span class="token function">run</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">--</span> 线程的运行代码方法
    <span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">--</span>线程的启动方法
    <span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">--</span>获取线程的唯一标识
    <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
    <span class="token function">sleep</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">--</span>线程的休眠 
    <span class="token function">interrupt</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">--</span>引发线程中断异常
    <span class="token keyword">yield</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">--</span>线程让步<span class="token punctuation">,</span>释放cpu资源<span class="token punctuation">,</span>重新抢占cpu资源<span class="token punctuation">,</span>谁抢到谁执行
    <span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">--</span>线程抢占<span class="token punctuation">,</span>抢占cpu资源<span class="token punctuation">,</span>指的是在那个线程里面调用该方法<span class="token punctuation">,</span>就是让那个线程休眠
    让调用<span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span>方法的线程先执行完毕
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="线程的休眠" tabindex="-1"><a class="header-anchor" href="#线程的休眠" aria-hidden="true">#</a> 线程的休眠</h5><p>Thread.sleep(毫秒值);</p><blockquote><p>必须指定毫秒时间值 , 是一个静态方法 Thread.sleep()，必须使用try...catch处理InterruptException异常</p></blockquote><h5 id="中断休眠的线程" tabindex="-1"><a class="header-anchor" href="#中断休眠的线程" aria-hidden="true">#</a> 中断休眠的线程</h5><p>Thread名 . interrupt();</p><blockquote><p>interrupt() --中断休眠的线程，引发InterruptException异常</p></blockquote><h5 id="线程让步" tabindex="-1"><a class="header-anchor" href="#线程让步" aria-hidden="true">#</a> 线程让步</h5><p>线程的让步: Thread.yield();</p><blockquote><p>使得当前线程让出CPU资源，让具有相同优先级的线程来获取CPU的执行权，但是不是绝对，因为有可能没有比当前线程优先级高的线程，当前的让步线程会被再次选中执行.</p></blockquote><h5 id="线程抢占" tabindex="-1"><a class="header-anchor" href="#线程抢占" aria-hidden="true">#</a> 线程抢占</h5><p>线程变量名 . join();</p><blockquote><p>A线程抢占B线程的CPU资源，线程B必须要等到线程A的代码全部执行完了才能继续执行</p></blockquote><h5 id="线程安全" tabindex="-1"><a class="header-anchor" href="#线程安全" aria-hidden="true">#</a> 线程安全</h5><p>多个线程在共享数据时，极可能会出现数据不安全情形，也是多线程的安全问题</p><p><strong>互斥锁</strong></p><p>原理：保证在一段时间内只允许一个线程执行同步锁定代码</p><p>a. 同步代码块 (推荐) b. 同步方法 -- 整个方法加锁</p><div class="language-java line-numbers-mode" data-ext="java"><pre class="language-java"><code><span class="token comment">// 同步 - java中关键字: </span>
<span class="token keyword">synchronized</span><span class="token punctuation">(</span> 对象 <span class="token punctuation">)</span><span class="token punctuation">{</span>              <span class="token punctuation">}</span>
<span class="token comment">// 互斥锁的使用方式：</span>
<span class="token number">1.</span> <span class="token class-name">Synchronized</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span>  当前对象锁标记
<span class="token number">2.</span> <span class="token class-name">Synchronized</span><span class="token punctuation">(</span>任意对象<span class="token punctuation">)</span> 任意对象的锁标记
<span class="token number">3.</span> <span class="token class-name">Synchronized</span><span class="token punctuation">(</span>类型<span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span> 类锁 
万物皆对象<span class="token operator">-&gt;</span>万物皆是锁 <span class="token operator">-&gt;</span> 对象互斥锁
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="线程的挂起" tabindex="-1"><a class="header-anchor" href="#线程的挂起" aria-hidden="true">#</a> 线程的挂起</h5><p>同步锁类型.wait() - 挂起</p><p>必须在同步锁里且类型一致,如果同步锁类型为this那挂起可省略类型 -&gt; wait()</p><p>挂起后再被唤醒时,会在挂起处开始执行而不是从头开始</p><h5 id="线程的唤醒" tabindex="-1"><a class="header-anchor" href="#线程的唤醒" aria-hidden="true">#</a> 线程的唤醒</h5><blockquote><p>同步锁类型.notif - 随机唤醒</p></blockquote><p>必须在同步锁里且类型一致,如果同步锁类型为this那挂起可省略类型 -&gt; notify()</p><blockquote><p>同步锁类型.notifyAll- 全部唤醒</p></blockquote><p>必须在同步锁里且类型一致,如果同步锁类型为this那挂起可省略类型 -&gt; notifyAll()</p><h4 id="死锁" tabindex="-1"><a class="header-anchor" href="#死锁" aria-hidden="true">#</a> 死锁</h4><blockquote><p>同步锁使用的弊端：</p></blockquote><p>当线程任务中出现了多个同步代码块(多个锁)时，如果同步代码块中嵌套了其他的同步代码块。这时容易引发一种现象：程序出现无限等待，这种现象我们称为死锁。这种情况能避免就避免掉。</p><h3 id="网络编程" tabindex="-1"><a class="header-anchor" href="#网络编程" aria-hidden="true">#</a> 网络编程</h3><blockquote><p>获取连接的客户端ip地址</p></blockquote><p>服务端变量名.getInetAddress();</p><h4 id="tcp-协议" tabindex="-1"><a class="header-anchor" href="#tcp-协议" aria-hidden="true">#</a> <strong>TCP-协议</strong></h4><h4 id="服务端" tabindex="-1"><a class="header-anchor" href="#服务端" aria-hidden="true">#</a> 服务端:</h4><p>1.创建服务器 new ServerSocket(5000 - 端口);</p><p>2.等待客户端连接 服务端变量名.accept();</p><p>3.流 客户端的信息输出至服务端的输入 | 获取客户端名 .getInputStream() 信息输出对应的客户端的输入 | 获取客户端名 .getInputStream()</p><p>4.关闭连接</p><h4 id="客户端" tabindex="-1"><a class="header-anchor" href="#客户端" aria-hidden="true">#</a> 客户端:</h4><p>1.创建客户端对象 new Socket(&quot;127.0.0.1&quot; - ip地址,5000 - 端口);</p><p>2.流 创建输入流连接到 - 服务端的输出流 | 客户端名 .getInputStream() 输入流放置在“流的末尾” | 客户端名 . shutdownInput() 创建输出流连接到 - 服务端的输入流 | 客户端名 .getOutputStream() 输出已结束 | 客户端名 .shutdownInput(); 解决服务端一值等待客户端输出数据</p><p>3.关闭连接</p></div></div><footer class="page-meta"><!----><div class="meta-item last-updated"><span class="xicon-container left meta-item-label"><!--[--><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" class="xicon-icon" style="width:20px;height:20px;font-size:20px;color:inherit;"><path d="M26 4h-4V2h-2v2h-8V2h-2v2H6c-1.1 0-2 .9-2 2v20c0 1.1.9 2 2 2h20c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 22H6V12h20v14zm0-16H6V6h4v2h2V6h8v2h2V6h4v4z" fill="currentColor"></path></svg><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Last Updated 2023-07-19 09:58:39<!--]--></span></span></div></footer><nav class="page-nav"><p class="hasPrev hasNext inner"><span class="page-nav-item prev"> ← 阿派的工具类</span><span class="page-nav-item next">Java 基础_进阶二 → </span></p></nav><!----></main><!--]--><div class="page-catalog-container"><h5 class="tip">文章层级目录</h5><ul><!--[--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#java-开发" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Java 开发"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java 开发<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#体系结构" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="体系结构:"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->体系结构:<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#标识符与关键字" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="标识符与关键字"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->标识符与关键字<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#java-基础字段" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Java 基础字段"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java 基础字段<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#数据类型" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="数据类型"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->数据类型<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#运算符" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="运算符"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->运算符<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#判断-迭代循环" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="判断 | 迭代循环"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->判断 | 迭代循环<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#判断-if-switch" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="判断 if - switch"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->判断 if - switch<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#循环-迭代" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="循环 迭代"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->循环 迭代<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#数组-方法" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="数组|方法"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->数组|方法<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#数组" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="数组"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->数组<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#方法" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="方法"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->方法<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#面对对象" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="面对对象"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->面对对象<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#类" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="类"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->类<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#对象" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="对象"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->对象<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#构造方法" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="构造方法"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->构造方法<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#构造语法" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="构造语法"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->构造语法<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#封装" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="封装"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->封装<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#继承" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="继承"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->继承<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#重写" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="重写"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->重写<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#super-关键字" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="super 关键字"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->super 关键字<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#final-关键字" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="final 关键字"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->final 关键字<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#抽象" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="抽象"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->抽象<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#接口" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="接口"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->接口<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#多重实现与继承" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="多重实现与继承"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->多重实现与继承<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#引用数据类型转换" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="引用数据类型转换"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->引用数据类型转换<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#多态" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="多态"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->多态<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#修饰符" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="修饰符"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->修饰符<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#执行顺序" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="执行顺序"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->执行顺序<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#匿名对象" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="匿名对象"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->匿名对象<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#匿名内部类" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="匿名内部类"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->匿名内部类<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#枚举" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="枚举"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->枚举<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#调用枚举字段" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="调用枚举字段"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->调用枚举字段<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#数据类型-及-api" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="数据类型 及 API"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->数据类型 及 API<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#object-类" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Object - 类"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Object - 类<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#基本数据类型的包装类" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="基本数据类型的包装类"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->基本数据类型的包装类<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#string-常用-api" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="String 常用 API"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->String 常用 API<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#arrays-数组" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Arrays | 数组"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Arrays | 数组<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#math-数学类" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Math | 数学类"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Math | 数学类<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#buffer-builder-字符串" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Buffer/Builder  | 字符串"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Buffer/Builder  | 字符串<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#date-时间" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Date | 时间"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Date | 时间<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#bigdecimal-精确计算" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="BigDecimal | 精确计算"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->BigDecimal | 精确计算<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#java-常用集合" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Java 常用集合"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Java 常用集合<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#范性" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="范性"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->范性<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#arraylist-集合" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="ArrayList 集合"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->ArrayList 集合<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#hashset-集合" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="hashset 集合"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->hashset 集合<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#hashmap-集合" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="hashmap 集合"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->hashmap 集合<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#collections-api" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Collections API"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Collections API<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#比较器" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="比较器"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->比较器<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#异常-自定义-jdbc" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="异常-自定义 | JDBC"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->异常-自定义 | JDBC<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#异常" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="异常"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->异常<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#自定义异常" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="自定义异常"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->自定义异常<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#jdbc-数据库" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="JDBC 数据库"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->JDBC 数据库<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#file-流" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="File|流 |"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->File|流 |<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#file-文件-目录" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="File 文件 | 目录"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->File 文件 | 目录<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#io-流" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="Io 流"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->Io 流<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--[--><li class="page-catalog-menu-depth_2"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#线程-网络编程" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="线程 | 网络编程"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->线程 | 网络编程<!--]--></span></span><!--[--><!--]--></a></li><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#多线程" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="多线程"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->多线程<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--[--><li class="page-catalog-menu-depth_3"><a aria-current="page" href="/docs/Java-develop/Java-basics.html#网络编程" class="router-link-active router-link-exact-active link page-catalog-item" aria-label="网络编程"><!--[--><!--]--><span class="xicon-container left"><!--[--><!----><!--]--><span class="xicon-content" style="color:inherit;font-size:14px;"><!--[-->网络编程<!--]--></span></span><!--[--><!--]--></a></li><!--]--><!--]--><!--]--></ul></div></div></div></div><!----><!----><!--]--></div>
    <script type="module" src="/assets/app-8a43a0f0.js" defer></script>
  </body>
</html>
